-
-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use query scope with hasManyDeepFromRelations? #36
Comments
It's not explicitly stated in the documentation, but You'll need to add the scope's constraint(s) manually: public function claims()
{
return $this->hasManyDeepFromRelations($this->companies(), (new Company)->claims())
->where('companies.active', true);
} |
This is working exceptionally well. Thank you for the quick response :) |
@staudenmeir Thanks for this awesome package. For this situation: Don't you think this is violating the DRY rule? Let's say I want to get all posts which is only published most cases. So if I forgot to add the publish constraint in hasManyDeepFromRelations then different query will behave different and there is no single source of control on a relationship. A lots of bug will be left under the hood. Do you think we can improve the issue? Thanks |
@hasnatbabur I agree, it wasn't a deliberate decision to not apply the constraints. The issue is quite complex and I'm still working on it. I see the automatic concatenation of foreign and local keys as the main benefit of |
I released public function claims()
{
return $this->hasManyDeepFromRelationsWithConstraints([$this, 'companies'], [new Company(), 'claims']);
} |
Thank you for this wonderful package. I just came to know about it recently and it has already made many parts of my code simpler.
I went through the documentation but there's one problem where I would appreciate some help.
I have the following relationship:
Now I was able to get the companies of the lawyer office by using hasManyDeepFromRelations as
But when I do the same for claims as
It ignores the active() query scope of the companies and returns claims of all the companies.
I assume this is something related to #35 but I am not sure where should I add the query scope manually.
Can you please guide me on how can I add query scope or where() condition in order to get the claims of the active companies of a lawyer office.
Thank you.
The text was updated successfully, but these errors were encountered: