Skip to content

Instantly share code, notes, and snippets.

@ericf
Created November 7, 2012 14:34
Show Gist options
  • Save ericf/4031948 to your computer and use it in GitHub Desktop.
Save ericf/4031948 to your computer and use it in GitHub Desktop.
Y.Order = Y.Base.create('order', Y.Model, [Y.ModelSync.REST], {
root: '/orders/',
initializer: function () {
this._products = new Y.ModelList({model: 'Product'});
},
_getProducts: function () {
return this._products;
},
_setProducts: function (products) {
return this._products.reset(products);
}
}, {
ATTRS: {
products: {
getter: '_getProducts',
setter: '_setProducts'
}
}
});
Y.Product = Y.Base.create('product', Y.Model, [], {}, {
ATTRS: {
name: {
value : null,
validator: Y.Lang.isString
},
price: {
value : 0,
validator: Y.Lang.isNumber
}
}
});
var myOrder = new Y.Order({
products: [
{name: 'Pen', price: 1.00},
{name: 'Paper', price: 1.50}
]
});
myOrder.save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment