Closed SychO9 closed 6 months ago
This sounds good. I think I'd like to call this scope
to be consistent with resources. Any reason to not allow it on ToOne
relationships too? (Move to the base Relationship
class)
Actually, just remembered that scope
is an Eloquent-specific behaviour so I'm not sure about including this functionality in the framework-agnostic Relationship
classes. I'll have a think about an alternative approach, maybe like making those classes macroable or something.
OK, I think the best approach will be to subclass the ToOne
and ToMany
classes under a new Tobyz\JsonApiServer\Laravel\Field
namespace, and both of them can use a trait which adds a scope
method. This way the concept of scoping remains entirely within the Laravel namespace.
Done 👍🏼
Thank you!
A better alternative to #102, generally allowing to constrain the relationship query during eager load is more flexible for use cases like the one outlined in the stale PR.