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
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! :)
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community