PDA

View Full Version : newb question #453: crossreference association



dedoz
14 Feb 2012, 1:03 PM
i have 2 models, they have a cross reference association ,
like saying user has many emails and email belongs to user.
and i get an error, loader says cant load '' (empty string) ;D

Example files

app/model/ModelType1.js


Ext.define('MUI.model.ModelType1', {
extend: 'Ext.data.Model',
requires : ['MUI.model.ModelType2'],
fields: ['id','name'],
hasMany :{ model: 'MUI.model.ModelType2', name:'model2'}
});


app/model/ModelType2.js


Ext.define('MUI.model.ModelType2', {
extend: 'Ext.data.Model',
requires : ['MUI.model.ModelType1'],
fields: ['id','name'],
belongsTo :{ model: 'MUI.model.ModelType1', name:'model1'}
});


a use file, just to isolate the problem


Ext.onReady(function() {

Ext.Loader.setConfig({enabled : true});
Ext.Loader.setPath('MUI','app');
Ext.require(['MUI.model.ModelType1']);

});


i just did a require, not even a create, just to check if the problem happens when loading my files.
triggers
Uncaught Error: The following classes are not declared even if their files have been loaded: ''. Please check the source code of their corresponding files for possible typos: '

so how can i do this ? its not posible ?

btw if i comment (//) the line from model2 that requires model1, theres no error, but then im forced to require model1 first to use model2,

tvanzoelen
14 Feb 2012, 1:06 PM
The property belongTo should be belongsTo.

dedoz
14 Feb 2012, 1:16 PM
yeah , edited, but that changed nothing
the problem is not there
is on the Ext.loader
loading files like
file1 requires file2 and file2 requires file1


i havent look that good at the Ext.loader source but i guess if we require
Ext.require('something')
check if something exists, if not, try to load .
Goin in
Ext.define('class1',
requires : 'class2'
)
loading class1.js and sees this definition, try to load class2.js
if class2 requires class1, and check for class1, it doesnt exist yet, its loading its dependency.

so i guess loader should ask "is already defined class1" OR " im loading its dependency?"
if any is true, dont load that file.
i guess is not checking second question, ill check source later :d

tvanzoelen
14 Feb 2012, 1:25 PM
Well probably it looks in MUI.model. Do you have that directory on the server?

I don't like these require statements that much. Isn't it possible you load these files in a ordinary a script tag?

dedoz
14 Feb 2012, 1:58 PM
Well probably it looks in MUI.model. Do you have that directory on the server?

I don't like these require statements that much. Isn't it possible you load these files in a ordinary a script tag?

Yes models are there, as i posted, if i comment // the line in model 2 that requires model 1, this triggers no errors and everything is loaded perfectly, but the reason for crossrefence is that i can instantiate one model (model1 or model2), if i comment that line i cant use model2 without loading "manually" model1.

for second comment
Ext.require is to load files dynamically, if you use script tag your loading the whole app at once, and maybe a user just want to use 1 thing of the 34535 things your app can do, is like using Microsoft Word (online version) and you download the whole MSWord, 42354256 mb when you enter to the site.

one of many diferences between desktop app and online app is that in the later one you need to worry bout what you are loading (data sent from the server to the client, data includes app code) if its a small app doesnt matter, but real world app you care bout this things, specially considering just Ext.js = like 2+ mb and if your customer wants to access from crappy inet conections its worst ;d

my english fails +1