PDA

View Full Version : Nested Models?



Bucs
29 Dec 2010, 7:44 AM
Can you create nested models where a property is an array of another model object? Take for instance the Cart, Product scenario. If I have the following objects defined:



Ext.regModel("Cart", {
fields: [
{name: 'custName', mapping: 'custName', type: 'string'},
{name: 'ordernumber', mapping: 'ordernumber', type: 'int'}
]

});

Ext.regModel("Product", {
fields: [
{name: 'productName', mapping: 'productName', type: 'string'},
{name: 'price', mapping: 'price', type: 'float'},
{name: 'qty', mapping: 'qty', type: 'int'}
]

});



Can I define a field in cart that contains many Products? If so, what exactly does the field type look like and how would I add the products to the Cart object? I know I can define the association like this in the cart object:



associations: [
{type: 'hasMany', model: 'Product', name: 'products'},
]


But does that become a "products" property of the Cart object into which I can add instances of product?

Don't see any model examples of exactly how to do this. Thanks!

Bucs
29 Dec 2010, 8:06 AM
Nevermind, this link here (http://dev.sencha.com/deploy/touch/docs/) explains it well enough :)

mitchellsimoens
29 Dec 2010, 3:10 PM
Nevermind, this link here (http://dev.sencha.com/deploy/touch/docs/) explains it well enough :)

haha, nice link

Bucs
29 Dec 2010, 3:12 PM
Oops...this might work better :)

http://dev.sencha.com/deploy/touch/docs/?class=Ext.data.BelongsToAssociation

sun713
14 Mar 2014, 3:17 PM
Both the links mentioned above are not working as they are for old ext versions. Can you please add the relevant link for 4.2 version.