Support the ongoing development of Laravel.io →
Database Eloquent Architecture
Last updated 2 years ago.
0

whereHas can't do it as it doesn't know what tables it should check. In fact polymorphic relations have some bugs, because of null passed to the constructor for example, that make morphTo unable to use some of the builder methods. You can't eager load such relation with additional constraints passed as a closure in with method and so on.

So basically you can query the other tables and eager load User for the results as a workaround

Last updated 2 years ago.
0

Thanks for the reply, I had a feeling that this was the case ... I did think about going at the data from the other tables, but that does seem a little weird, but as you say .. its a work around..

thanks for the help! :)

Last updated 2 years ago.
0

Hi, Can I ask how your DB schema looks like for morphOne()? I'm not sure how this is suppose to work. In my case I have an orders table which has an address_id foreign key to the addresses table. But I also have an organisations table that also contains an address_id foreign key.

Are these the only requirements to make morphOne() relationship work?

Further I shouldn't have hasOne() and belongsTo() if I'm using morphOne() correct?

UPDATE: I think I get it now. I missed a section in the docs that explained this.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

bagwaa bagwaa Joined 13 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.