# 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 a `Batman.AssocationProxy` named after the association type,
such as `Batman.BelongsToAssociationProxy` or `Batman.HasManyAssociationProxy`.

`Batman.AssociationProxy` defines useful methods such as `@load`, `@toJSON`, `@loadFromLocal`. It also defines accessors such as `%loaded` and `%target`.

## Shared Options
All assocations have a common set of options, as well as specific options for each type of relationship.

##### `saveInline[= true] : boolean`
Whether we should save the child objects as part of the parent object's JSON

##### `autoload[= true] : boolean`
 Whether we should load the child objects when loading the parent object.

##### `nestUrl[= false] : boolean`
Whether the child models are persisted beneath the parent models url structure.

##### `name : String`
The name of the child model for the association. (eg. App.Product)

##### `inverseOf : String`
The foreign association to set on load.

##### `encoderKey : String`
The key to encode and decode the assocation into/from JSON.

##### `namespace[= Batman.currentApp] : String`
The location of the model definition for the association.

##### `polymorphic[= false] : boolean`
Whether the association is polymorphic.

## @hasMany(label[, options])
`hasMany` assocations are used for expressing one-to-many relationships on a `Batman.Model`.

- `label : String`
- `options : Object`
  - `primaryKey : String`
  - `foreignKey : String`
  - `as : String`
    - the parent association name on child objects in a polymorphic association

## @hasOne(label[, options])
`hasOne` associations are used for expressing one-to-one relationships on a `Batman.Model`.

- `label : String`
- `options : Object`
  - `primaryKey : String`
  - `foreignKey : String`
  - `as : String`
    - the parent association name on child objects in a polymorphic association

## @belongsTo(label[, options])
`belongsTo` associatons are used fro expressing one-to-one child relationships on a `Batman.Model`.

- `label : String`
- `options : Object`
  - `primaryKey : String`
  - `foreignKey : String`
  - `encodeForeignKey[= true] boolean`
    - whether to encode the foreignKey value when persisting the model
getshuvo/batman,getshuvo/batman