Skip to content

Propagate parse option to nested models #11

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

Open
sobrinho opened this issue May 19, 2014 · 3 comments
Open

Propagate parse option to nested models #11

sobrinho opened this issue May 19, 2014 · 3 comments

Comments

@sobrinho
Copy link
Contributor

Example:

Schedule = Backbone.Model.extend({
  parse: function (attributes) {
    attributes.at = moment(attributes.at);

    return attributes;
  }
});

Agenda = Backbone.NestedModel.extend({
  relations: [
    {
      type: "one",
      key: "schedule",
      relatedModel: function () { return Schedule }
    }
  ],

  parse: function (attributes) {
    attributes.created_at = moment(attributes.created_at);

    return attributes;
  }
});

new Agenda(window.agenda, { parse: true });

Agenda.prototype.parse is called but Schedule.prototype.parse don't.

Do you think that makes sense to propagate the options from the higher model to lower models?

@vicentemundim
Copy link
Member

I think it does, currently it does not pass options when setting values for nested objects.

@sobrinho
Copy link
Contributor Author

Nope, take a look here.

It instantiates a new object without the options object.

@vicentemundim
Copy link
Member

It makes sense to pass options. For consistency it should do it for has_many relationships as well. Could you prepare a pull request with these changes?

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

No branches or pull requests

2 participants