default withRelated by Model
See original GitHub issueWith bookshelf 0.8.x I append default relation in fetch with this code:
initialize: function() {
this.on('fetching fetching:collection', function(model, columns, options) {
if (!options.withRelated) {
options.withRelated = [];
}
options.withRelated.push("country");
}
but in ‘bookshelf’ 0.10.2 not work, some alternative for default relation?
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
API Reference - Bookshelf.js
Default behavior const MyModel = bookshelf.model('MyModel', ... load attributes onto a Model , in a similar way that the withRelated option works on...
Read more >Always fetch from related models in Bookshelf.js
The following works for me but it seems that withRelated will load relations if baffle model is fetched directly, not by relation:
Read more >Query examples | Objection.js
All queries are started with one of the Model methods query, $query, relatedQuery or ... By default upsertGraph method updates the objects that...
Read more >Working with Related Objects - SQLAlchemy 1.4 Documentation
Working with Related Objects ... They may be also configured as defaults for a relationship() using the relationship.lazy option, e.g.:.
Read more >Model Factory Class with Attaching Relationship By Default
For example if you notice inside of the active method I am attaching the child models with related data. The problem is I...
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
This seems to be fixed with the latest version. Either that or there is some information missing from this issue.
Check PR #1853 for a test case that is similar to the mentioned steps to reproduce.
To reproduce this error you need some table like
city
with a foreign key tocountry
and the above code always when
city
is fetched (new City({'id': 1})
) adds as relationcountry
for getting something like: