Record with hasMany association is not set to dirty #247

Closed
pangratz opened this Issue May 7, 2012 · 4 comments

Comments

Projects
None yet
2 participants
Member

pangratz commented May 7, 2012

I would expect the post to be dirty when an object is added to a hasMany association, see http://jsfiddle.net/pangratz666/Zghuz/.

App = Ember.Application.create({});

App.Comment = DS.Model.extend({
    text: DS.attr('string')
});

App.Post = DS.Model.extend({
    text: DS.attr('string'),
    comments: DS.hasMany('App.Comment')
});

App.store = DS.Store.create({
    revision: 4
});

App.store.load(App.Post, {id: 1, text: 'first post'});
App.store.load(App.Comment, {id: 2, text: 'first comment'});

var post = App.Post.find(1);
console.log('post is dirty', post.get('isDirty'));
console.log('number of comments', post.getPath('comments.length'));

var comment = App.Comment.find(2);

var comments = post.get('comments');
comments.pushObject(comment);

console.log('post is dirty', post.get('isDirty')); // Y U NO DIRTY?
console.log('number of comments', post.getPath('comments.length'));​
Member

tchak commented May 7, 2012

not it is the comment that gets dirty, this not a bug
belongsTo define the foreignKey

Member

pangratz commented May 7, 2012

Thanks for you quick reply @tchak !

My backend is a CouchDB and the foreign keys are defined in the Post model like stated in the example. Is there a way to get this working with the current ember data?

I have seen #53 and @wycats latest response. Will those kind of nested hasMany associations be possible when #53 is closed?

Member

tchak commented May 7, 2012

I think what you looking for is #195, and yes it looks like it all will be adressed by upcoming redesign

Member

pangratz commented May 8, 2012

Okay, thanks again!

@pangratz pangratz closed this May 8, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment