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

default withRelated by Model #1445

Closed
ghost opened this issue Nov 4, 2016 · 5 comments
Closed

default withRelated by Model #1445

ghost opened this issue Nov 4, 2016 · 5 comments
Assignees
Labels

Comments

@ghost
Copy link

ghost commented Nov 4, 2016

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?

@jamesdixon
Copy link

@vxcamiloxv did you ever get this to work properly?

This also doesn't work for me using Bookshelf 0.12.1.

@ricardograca
Copy link
Member

ricardograca commented Mar 9, 2018

It looks like the code that handles this event has been like that since about version 0.8.2. Also, from looking at the code I see no reason why this wouldn't work, but I haven't looked too deeply or investigated much.

Can any of you provide a reproducible test case for this issue?

@ghost
Copy link
Author

ghost commented Mar 9, 2018

In 0.8.x works fine but in 0.12.1 I was getting Maximum call stack size exceeded

@ghost
Copy link
Author

ghost commented 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"
  }
 } 
}

@ricardograca
Copy link
Member

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.

@ricardograca ricardograca self-assigned this Jun 1, 2018
@ricardograca ricardograca moved this from To Do to In progress in Version 0.14.0 Jun 1, 2018
Version 0.14.0 automation moved this from In progress to Done Jun 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Development

No branches or pull requests

2 participants