Skip to content
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

Controller hooks for modifying relationships should receive the relation value #17

Closed
lindyhopchris opened this issue Feb 5, 2021 · 1 comment

Comments

@lindyhopchris
Copy link
Contributor

As per this issue:
cloudcreativity/laravel-json-api#264

The controller hooks for modifying a relation should receive the relation value. We can use the LazyRelation value here, just like the authorizers.

The LazyRelation class actually caches its value internally for a to-many relation. We should add caching of the to-one relation as well. Then we should keep the instance on the request, so that the same instance is used for both the authorization and the controller hooks: meaning there would only be one database request if the relation is accessed in both the authorization code and the controller hook.

@lindyhopchris lindyhopchris added this to the v1.0.0-alpha.3 milestone Feb 6, 2021
@lindyhopchris
Copy link
Contributor Author

Actually don't think I want to make any changes at this stage. The second hook (after the relationship is updated) has access to the models that replaced, added-to or removed-from the relation. The main issue with providing them to the before hook is that the records aren't materialized at that point.

I would need a really good use-case to make changes, as the whole point with the current set up is that the JSON:API identifiers are passed down to the repository, which takes care of resolving them and modifying the relationship. It feels like use-case would be solved by using the after hook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant