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

toJSON with sub relations models #469

Open
anthonybriand opened this issue Jun 5, 2014 · 0 comments
Open

toJSON with sub relations models #469

anthonybriand opened this issue Jun 5, 2014 · 0 comments

Comments

@anthonybriand
Copy link

Hello,

I met a particular case, I have a model that contains hasOne relationships which in themselves have same relationships.

The problem was that the toJSON took over the includeInJSON for the model but not for the related models

I propose to put this code in the toJSON function :

if(related.get( key ) instanceof Backbone.Model && _.isFunction(related.get( key ).toJSON)){ value[ key ] = related.get( key ).toJSON(options); var nValue = {}; var subInJSON = related.getRelation(key).options.includeInJSON; for(var nkey in subInJSON){ nValue[subInJSON[nkey]] = value[key][subInJSON[nkey]]; } value[key] = nValue; }else{ value[ key ] = related.get( key ); }

Sorry for my English

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

No branches or pull requests

2 participants