I'm trying to create an empty record along with empty associated records.
Here's a fiddle: http://jsfiddle.net/brancusi/NQKvy/629/
App = Ember.Application.create({});
App.IndexRoute = Ember.Route.extend({
model: function(){
return this.createEmptyInventory();
},
createEmptyInventory: function(){
var stockLevels = []
var product1 = this.store.createRecord('product', {name:"Cheese Pizza"});
var product2 = this.store.createRecord('product', {name:"Mushroom Pizza"});
var product3 = this.store.createRecord('product', {name:"Calzone"});
var products = [product1, product2, product3]
var stockLevelList = []
scope = this;
Ember.EnumerableUtils.forEach(products, function(item){
var stockLevel = scope.store.createRecord('product_stock_level', {
product:item,
quantity:0
});
stockLevelList.addObject(stockLevel);
});
var inventory = this.store.createRecord('inventory', {
testProp:"TestVal",
productStockItems:stockLevelList
})
console.log(stockLevelList);
console.log(inventory.get('productStockLevels'));
return inventory;
}
});
// Models
App.Inventory = DS.Model.extend({
productStockLevels:DS.hasMany('product_stock_level'),
testprop:DS.attr('string')
});
App.ProductStockLevel = DS.Model.extend({
inventory:DS.belongsTo('inventory'),
product:DS.belongsTo('product'),
quantity:5
});
App.Product = DS.Model.extend({
productStockLevels:DS.hasMany('product_stock_level'),
name:DS.attr('string')
});
So I notice that there is no ID, and I'm guessing that's how ember does all its associations?
How should I generate a temporary record like this?
If the user abandons this, I don't want to persist anything to the DB, I just want to then dump that record.
I'm basically trying to simulate a Rails: Inventory.new