Closed azorgh closed 8 years ago
i have the some problem.....
+1
From what I've read, whereHas doesn't support polymorphic relations. Did anyone else come to that conclusion?
well at the time i was looking for this whereHas stuff... and it wasnt working the way i expected... i come out with a different approach which works great for my case.. have a look.
public function scopeActive(Builder $query)
{
foreach ($stages = ['idea', 'synapse', 'script'] as $stage) {
$query->orWhereHas(array_shift($stages), function (Builder $query) {
$query->where('active', true)->orHas('submission');
});
foreach ($stages as $model) {
$query->whereDoesntHave($model);
}
}
$query->where('active', true);
}
my polymorphism relation is like this Project -> ['idea', 'synapse', 'script'] -> its like levels... 1 2 3 u cant have the 3 before having the 2 ..
Thanks for sharing this. Something like this might fit my needs, too.
+1 ...I would love to be able to use whereHas on polymorphic relations
+1 here.
Closing since this is a feature request, not a bug report. If you have an implementation idea, please open an issue on internals.
Hi!
I use Laravel 5.2.45, seems it haven't fixed yet. Perhaps in future will be good to throw Exception or write a note in the documentation about such behaviour.
Best regards.
+1 for this please!
+1
+1
+1
Hi +1
Hi guys.
I'm trying to make a Eloquent request with polymorphic relations and conditions. So, I have models :
$this->morphTo())
=> detail method)$this->morphOne(MainClass::class)
)$this->morphOne(MainClass::class)
)In my example, I must get only MainClass where 'column' in my polymorphic relation was null. So, i wrote this :
But a QueryException was thrown:
Except this conditions, all polymorphic relations works perfectly.
I'm sorry if it's not a bug, but all my app works well without this condition ! Thanks (and good luck :) )
PS: I'm using Laravel 5.2.32.