question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

default withRelated by Model

See original GitHub issue

With 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:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ricardogracacommented, Jun 1, 2018

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.

0reactions
vxcamiloxvcommented, Mar 9, 2018

To reproduce this error you need some table like city with a foreign key to country

  • City table
------------------------------
id | name    | country_id
------------------------------
1  | Bogotá  | 2
------------------------------
  • Country table
------------------------------
id | name       | locale 
------------------------------
1  | Mexico     |  es_MX
------------------------------
2  | Colombia   |  es_CO
------------------------------

and the above code always when city is fetched (new City({'id': 1})) adds as relation country for getting something like:

{
  city: {
   id: 1,
   name: "Bogotá",
   country: {
     id: 2,
     name: "Colombia",
     locale: "es_CO"
  }
 } 
}
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found