Skip to content

Instantly share code, notes, and snippets.

@dhruvaray
Created October 18, 2013 09:55
Show Gist options
  • Save dhruvaray/7039272 to your computer and use it in GitHub Desktop.
Save dhruvaray/7039272 to your computer and use it in GitHub Desktop.
Pass options to relations
var Employee = Backbone.AssociatedModel.extend({
parse:function (obj) {
if (obj.sex === "M") {
obj.prefix = "Mr.";
}
return obj;
}
});
var Company = Backbone.AssociatedModel.extend({
relations:[
{
type:Backbone.Many,
relatedModel:Employee,
key:'employees',
options:{
parse:true // set relation options
}
}
]
)};
var c = new Company();
c.set("employees", [
{
name: "John",
sex: "M"
}
]);
console.log(c.get("employees[0].prefix")); // Mr.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment