emberjs/data — pull request #1457 by Cyril-sf (2013-10-17 23:02:47+00:00)
Title: Add support for polymorphic hasMany associations.

Saving async polymorphic associations is not currently supported.

Fixes the payload required by the ActiveModelAdapter to match the
Rails ActiveModel Serializers.

```js
MyUser = DS.Model.extend({
name: DS.attr('string'),
messages: DS.hasMany('myMessage', {
polymorphic: true,
inverse: 'user'
})
});

MyMessage = DS.Model.extend({
name: DS.attr('string')
comments: DS.hasMany('myComment', {
inverse: 'message'
}),
user: DS.belongsTo('myUser')
});

MyPost = MyMessage.extend({
});

MyComment = MyMessage.extend({
message: DS.belongsTo('myMessage', {
polymorphic: true,
inverse: 'comments'
})
});
```

The expected payload for a polymorphic `belongsTo` association is then:

```js
my_comment: [{
id: 2,
name: "Rails is omakase",
message: {
type: 'my_post',
id: 1
}
}],

my_posts: [{
id:1,
name: "OMG"
}]
```

The expected payload for a polymorphic `hasMany` association is then:

```js
my_user: [{
id: 1,
name: "Cyril Fluck",
messages: [{
type: 'my_post',
id: 1
}, {
type: 'my_comment',
id: 2
}]
}],

my_posts: [{
id:1,
name: "OMG"
}],

my_comments: [{
id: 2,
name: "Rails is omakase"
}]
```