Allow withRelated functions to be executed for nested relations
See original GitHub issueCurrently, if I specify that a relationship should be eager loaded on a fetch, it’s possible to specify an object within the “withRelated” list passed to the fetch options, and this can be used to modify the query used when loading a particular relation. However, this only works for single-level relationships.
This is a feature request, to make this work for multiple levels. One possible solution would be to allow specifying an array of functions, and pop the array and pass to the next level of the relation loading.
Eg.
model.fetch({
withRelated: [
{'relation1.subrelation': [null, (query) => { query.sortBy('id'); }]}
]
});
Which would not execute anything when loading “model.relation1”, but would execute the provided function when loading “relation1.subrelation”.
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
node.js - Retrieving deeply nested relations using bookshelf's ...
Before I post all of the code and associated DB models is it possible to go deeply nested like this or can bookshelf...
Read more >Eloquent: Relationships - The PHP Framework For Web Artisans
Dynamic properties allow you to access relationship functions as if they were properties defined on the model: $phone = User::find(1)->phone;.
Read more >Query examples | Objection.js
However, allowing the client to execute expressions like this without any limitations is not very secure. Therefore the QueryBuilder has the allowGraph method....
Read more >Laravel (5.7) Eloquent Relationships - w3resource
In defining this relationship, we need three database tables: users, roles, and role_user. The role_user table will be derived from the ...
Read more >API Reference - Bookshelf.js
Override this in your bookshelf instance to define a custom function that will ... You can also execute callbacks on relations queries (eg....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Actually if you look the implementation then this should work as well.
The project leadership of Bookshelf recently changed. In an effort to advance the project we close all issues older than one year.
If you think this issue needs to be re-evaluated please post a comment on why this is still important and we will re-open it.
We also started an open discussion about the future of Bookshelf.js here https://github.com/bookshelf/bookshelf/issues/1600. Feel free to drop by and give us your opinion. Let’s make Bookshelf great again