Closed dottodot closed 9 years ago
Hello
Thanks for your interest in my plugin - good to see it getting noticed a little!
To make use of the association functionality, you'll need to declare the associations as part of your Backbone.Sails.Model
definition:
var Team = Backbone.Sails.Model.extend({
assoc: {
users: UserCollection
}
})
assoc
keeps reference to the constructor's used to wrap raw data given and received by the API. You can also pass a string (the modelName
), or an array of a string to indicate an associated collection:
var Team = Backbone.Sails.Model.extend({
assoc: {
users: ['user'] // associated collection with modelName of `user`,
captain: 'user' // associated model
}
})
(You can also pass a function taking no arguments returning a Model
or Collection
for circular references)
If that doesn't solve the problem, could you please send me some more info. A stack trace would be ideal, along with your model definitions.
That's great, went with the second option and that work perfectly.
Firstly thank you for what looks to be an amazing plugin.
Just having a little difficulty using the addTo feature. I'm trying to add and existing model to another model which has a many to many association.
but I get an error of Uncaught TypeError: Cannot read property 'users' of undefined
team has already been fetch and users populated.
I'm not sure if misinterpreting to use of addTo or doing something wrong.