Skip to content

belongsTo/hasMany createRecord vs set behavior difference #529

Closed
leepfrog opened this Issue Dec 16, 2012 · 8 comments

7 participants

@leepfrog

It appears that when you use createRecord() and set belongsTo attributes, the hasMany side of the association does not get the newly created record.

If you use set(), everything works as expected.

@wagenet
Ember.js member
wagenet commented Jan 10, 2013

@leepfrog Is this still an issue in master?

@leepfrog

let me test and get back to you

@sly7-7
sly7-7 commented Jan 18, 2013

@leepfrog 👍, you're not alone ;), you know sometimes with ember-data, things are working as exapected (I'm pretty sure I've seen createRecord(parent_id: 1) working), sometimes not. Here is an updated version of your fiddle, demonstrating two ways of populating the many arrays: http://jsfiddle.net/DKevG/3/

@mspisars

👍 still an issue on latest...

@ftokarev

A possible fix is given in #544

@ashugit
ashugit commented Feb 20, 2013

I am having a problem with createRecord.
I have this relation
App.Contact = DS.Model.extend({
test: DS.belongsTo('App.Test')
})

App.Test = DS.Model.extend({
text: DS.attr('string'),
contact: DS.belongsTo('App.Contact')
})

Test is embedded always in Contact.

I am trying to create a new model object by calling transaction.createRecord(App.Contact), it fails to create Test object. If I make the relation Contact -hasOne-> Test to Contact -hasMany-> Test I am able to call createRecord.

I am not sure how to call createRecord for a new model object for the parent such that all children in one-to-one relationship get initialized.

Please help.

@igorT
Ember.js member
igorT commented Apr 15, 2013

This is a bug related to the broader problem of syncing relationships. A whole class of these problems should be fixed by a refactor that I will start working on in couple weeks. Closing as a duplicate of #695.

@igorT igorT closed this Apr 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.