PDA

View Full Version : Model Asscociations without full path?



rfox
25 Nov 2011, 4:56 AM
Hi, I've setup quite a lot of models within an MVC app, so i split them into folders eg:


app
model
category1
model1
model2
category2
model3
model4

This works in controllers I can reference them like so:

models:['category1.model1'...
but given an asscociations within model 1 for example:

associations: [ { type:'belongsTo', model: 'category1.model1'} ]
The model object is defined without any asociation data, ive outputted it to firebug to inspect it and the model has no associations.

I can fix this by using the full ath to the model:

associations: [ { type:'belongsTo', model: 'appname.model.category1.model1'} ]

this however makes the association functions really really ugly:

model2.getappname.model.category.model1()
They also dont work. Firebug reports model2.getappname is undefined :(

Is there anyway to sort out associations so that they work within folders and are tidy(or at least tidier) ?eg:

model2.getModel1()

If more information is required i can paste my model declarations, screenshot my folder structure and screenshot the json object in the dom tab of firebug.

Thanks :D

tobiu
25 Nov 2011, 5:43 AM
you have a name config, example:


hasMany: {model: 'Product', name: 'products'}


your code:


getappname.model.category.model1()


should never ever work!


getAppnameModelCategoryModel1()


makes hopefully more sense :)

rfox
25 Nov 2011, 6:24 AM
Ahh the name field, Completely forgot about it. Awesome thanks again :D


SECOND EDIT:

I found http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.BelongsToAssociation-cfg-getterName

which fixes the above.