0
votes

I'm using a rest adapter with ember-data 1.0 and ember.js 1.0

given these models:

App.Customer  = DS.Model.extend({
    name: DS.attr('string'),
    state: DS.belongsTo("State")
});


App.State  = DS.Model.extend({
   region: DS.attr('string'),
   state: DS.attr('string'),
   stateName: DS.attr('string'),
   customers: DS.hasMany("Customer")
});

when I go to /#/states, I get this json response

{
  "states": [
 {
  "region": "West",
  "state": "AZ",
  "stateName": "Arizona",
  "id": "0x0000000000000324",
  "customers": [
    "0x00000000000001e5"
  ]
},
{
  "region": "West",
  "state": "CA",
  "stateName": "California",
  "id": "0x0000000000000325",
  "customers": [
    "0x00000000000001c0",
    "0x00000000000001c4",
    "0x00000000000001d4"
  ]
 }
]

"customers" : [
 {
 }
 ]
}

Now, I have a couple of questions

1) What should I put in the Customers part ? A complete list of all the customers, or just a list of the customers that are specified in the state list ?

2) what data should I send back if I visit /#/customers ?

3) If I were to edit a customer. would I set it up so that the lookup/combo makes a separate request to the server ?

thanks for the help !

1

1 Answers

0
votes

1) In your original JSON the customers array should only contain customers who are present in the state list.

2) This depends on your app. Generally you would want /customers to return all customers. Or maybe a paginated collection of customers. Or maybe only customers that the currently logged in user is allowed to see. Etc...

3) When you edit a customer Ember should already have the customer data loaded, so no additional lookup request should be required.