rickard2
rickard2

Reputation: 291

Two way one to one associations in Ember Data

In my application I'm having two way 1:1 relationships between models. When trying to set an association between them i get ...

Uncaught RangeError: Maximum call stack size exceeded

... and the trace repeats

OrderedSet.forEach
Map.forEach
DS.Model.Ember.Object.extend.toJSON
DS.Model.Ember.Object.extend.addBelongsToToJSON
DS.Model.Ember.Object.extend.toJSON
Map.forEach
OrderedSet.forEach

Relevant parts of the code:

App.Employee = DS.Model.extend( {
    // ... 
    recruitment:DS.belongsTo( 'App.Recruitment', { embedded: true } )
} );

App.Recruitment = DS.Model.extend( {
    // ...
    employee:DS.belongsTo( 'App.Employee', { embedded: true } ),
} );

// ...

recruitment.set('employee', employee);
employee.set('recruitment', recruitment);
App.store.commit(); // <= boom

Is this something that Ember Data should support or am I approaching this all wrong?

Upvotes: 1

Views: 614

Answers (2)

ansorensen
ansorensen

Reputation: 1316

This has been fixed, and is now a straight-forward process of making the models belong to each other:

App.User = DS.Model.extend({
  profile: DS.belongsTo('profile')
});

App.Profile = DS.Model.extend({
  user: DS.belongsTo('user')
});

The above is an example from http://emberjs.com/guides/models/defining-models/

Upvotes: 0

Tchak
Tchak

Reputation: 126

Ember-Data does not support one-to-one associations at the moment.

Upvotes: 2

Related Questions