Note that there are some explanatory texts on larger screens.

plurals
  1. POHow and when to fetch many-to-many relationships objects from server
    primarykey
    data
    text
    <p>I'm having some issue with my Ember web application. I'm using Ember 1.0 stable as the base JS framework and Ember-data.js 1.0 beta 1 to handle the relationships between model and the CRUD operations.</p> <p>My simple application manages two entities: User and Order with a many to many relationship between them.</p> <p>Here are the models:</p> <pre><code> /*User Model*/ App.User = DS.Model.extend({ first_name: DS.attr('string'), last_name: DS.attr('string'), fullName: function() { return this.get('first_name') + ' ' + this.get('last_name'); }.property('first_name', 'last_name'), userorders: DS.hasMany('userorder', {async: true}) }); /*Order Model*/ App.Order = DS.Model.extend({ description: DS.attr('string'), userorders: DS.hasMany('userorder', {async: true}) }); </code></pre> <p>I created the model Userorder which maintains the one-to-one relationships with both User and Order.</p> <p>Here is the model for Userorder:</p> <pre><code> App.Userorder = DS.Model.extend({ order: DS.belongsTo("order", {async: true, key: "order_id"}), user: DS.belongsTo("user", {async: true, key: "user_id"}) }); </code></pre> <p>My problem comes up when i try to get (into UserorderRoute) the single instance of a usersorder. Follows the code for UserorderRoute:</p> <pre><code>App.UserorderRoute = Ember.Route.extend({ model: function(params) { return this.store.find("userorder", params.userorder_id); } }); </code></pre> <p>The userorder instance is correctly fetched, but if I try to access to the 'order' object I get undefined, (obviously, I get the same behavior with the access to 'user').</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload