Skip to content

Instantly share code, notes, and snippets.

@cloke
Created January 13, 2013 05:40
Show Gist options
  • Save cloke/4522521 to your computer and use it in GitHub Desktop.
Save cloke/4522521 to your computer and use it in GitHub Desktop.
#Model
Diets.FoodNutrient = DS.Model.extend
amount: DS.attr 'string'
name: DS.attr 'string'
nutrient_id: DS.attr 'string'
Diets.Food = DS.Model.extend
brand: DS.attr 'string'
food_nutrients: DS.hasMany( Diets.FoodNutrient )
DS.RESTAdapter.map( Diets.Food, {
food_nutrients: { embedded: 'always' }
})
#Controller to create new related record
addNutrient: (model) ->
@get('selection.food_nutrients').createRecord { name: 'my name' }
#Data - Removed some properties above to keep things short.
{"food":{"brand":"Fage 1","name":"Total 2% Greek Strained Yogurt","serving_size":"227 g","additional_serving_size":"1 cup","tags":[],"updated_at":"2012-07-08T04:41:59.773Z","id":"4f9353b8c3f41c7686000001","food_nutrients":[{"name":"fat","amount":"4.5 g","nutrient_id":null,"id":"50f1e53f0a98dab25200002a"},{"name":"saturated fat","amount":"3 g","nutrient_id":null,"id":"50f1e53f0a98dab25200002b"},{"name":"cholesterol","amount":"15 mg","nutrient_id":null,"id":"50f1e53f0a98dab25200002c"},{"name":"sodium","amount":"75 mg","nutrient_id":null,"id":"50f1e53f0a98dab25200002d"},{"name":"carbohydrate","amount":"9 g","nutrient_id":null,"id":"50f1e53f0a98dab25200002e"},{"name":"sugar","amount":"9 g","nutrient_id":null,"id":"50f1e53f0a98dab25200002f"},{"name":"protein","amount":"23 g","nutrient_id":null,"id":"50f1e53f0a98dab252000030"},{"name":"vitamin a","amount":"12.000 u","nutrient_id":null,"id":"50f1e53f0a98dab252000031"},{"name":"calcium","amount":"1.250 g","nutrient_id":null,"id":"50f1e53f0a98dab252000032"}]}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment