Skip to content

Commit

Permalink
Support for manyToNone and manyToMany relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
ssured committed Sep 3, 2013
1 parent cb3943b commit 7f752ad
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/ember-data/lib/serializers/json_serializer.js
Expand Up @@ -120,7 +120,16 @@ DS.JSONSerializer = Ember.Object.extend({
}
},

serializeHasMany: Ember.K,
serializeHasMany: function(record, json, relationship) {
var key = relationship.key;

var relationshipType = DS.RelationshipChange.determineRelationshipType(record.constructor, relationship);

if (relationshipType === 'manyToNone' || relationshipType === 'manyToMany') {

This comment has been minimized.

Copy link
@kingpin2k

kingpin2k Dec 21, 2013

Contributor

What was the reasoning behind excluding manyToOne? was it to stop recursion in an embedded save?

This comment has been minimized.

Copy link
@ssured

ssured Dec 21, 2013

Contributor

manyToOne is saved on the inverse side, see serializeBelongsTo. Ember Data merges the records once loaded.
If you need to store the relation on the hasMany, you can extend this function.

This comment has been minimized.

Copy link
@kingpin2k

kingpin2k Dec 21, 2013

Contributor

Yes, I saw how it functions. I don't need it, I keep having to inform people on stackoverflow that they need to override to include the ids. Is there any reason the belongsTo side was chosen over the hasMany? And since model's aren't embedded anymore is there any downside to including the ids on the hasMany side?

This comment has been minimized.

Copy link
@ssured

ssured via email Dec 21, 2013

Contributor

This comment has been minimized.

Copy link
@kurko

kurko Dec 28, 2013

Contributor

I also came here today to figure out the reason why manyToOne wasn't included here. It breaks the FixtureAdapter expectations.

Monkey patching the condition to add manyToOne fixed my problems.

This comment has been minimized.

Copy link
@mattaddy

mattaddy Apr 18, 2014

Is this a bug or a feature? Adding an object to a hasMany array doesn't persist after save() if the corresponding record declares a belongsTo.

This comment has been minimized.

Copy link
@JFickel

JFickel Apr 21, 2014

+1. What? I was pretty surprised by this behavior.

This comment has been minimized.

Copy link
@neverfox

neverfox Apr 22, 2014

Same. It basically breaks the expected behavior of emberfire, which is how I discovered this.

json[key] = get(record, key).mapProperty('id');
// TODO support for polymorphic manyToNone and manyToMany relationships
}
},

// EXTRACT

Expand Down

0 comments on commit 7f752ad

Please sign in to comment.