Batman.Model Associations
There are 3 types of assocations available on Batman.Model: hasMany, belongsTo, and hasOne.
-
Batman.AssocationProxy
Association accessors won't always return a
Batman.Set. Generally they will return aBatman.AssocationProxynamed after the association type, such asBatman.BelongsToAssociationProxyorBatman.HasManyAssociationProxy.Batman.AssociationProxydefines useful methods such as@load,@toJSON,@loadFromLocal. It also defines accessors such as%loadedand%target. -
Shared Options
All assocations have a common set of options, as well as specific options for each type of relationship.
saveInline[= true] : booleanWhether we should save the child objects as part of the parent object's JSON
autoload[= true] : booleanWhether we should load the child objects when loading the parent object.
nestUrl[= false] : booleanWhether the child models are persisted beneath the parent model's url structure.
name : stringThe name of the child model for the association. (eg. App.Product)
inverseOf : stringThe foreign association to set on load.
encoderKey : stringThe key to encode and decode the assocation into/from JSON.
namespace[= Batman.currentApp] : stringThe location of the model definition for the association.
polymorphic[= false] : booleanWhether the association is polymorphic.
-
@hasMany(label[, options])
hasManyassocations are used for expressing one-to-many relationships on aBatman.Model.label : stringoptions : ObjectprimaryKey : stringforeignKey : stringas : string- the parent association name on child objects in a polymorphic association
-
@hasOne(label[, options])
hasOneassociations are used for expressing one-to-one relationships on aBatman.Model.label : stringoptions : ObjectprimaryKey : stringforeignKey : stringas : string- the parent association name on child objects in a polymorphic association
-
@belongsTo(label[, options])
belongsToassociatons are used for expressing one-to-one child relationships on aBatman.Model.label : stringoptions : ObjectprimaryKey : stringforeignKey : stringencodeForeignKey[= true] boolean- whether to encode the foreignKey value when persisting the model
