View Full Version : Failed to find association/belongsto

15 Oct 2012, 5:30 AM
I've started to use the sencha command for my now fairly big project (should have started earlier but hey, better late then never ;-)). I've created my all-classes.js using sencha app build
Anyway, I get issues with my models due to missing the BelongsTo and HasMany associations.
When load my app it tries to find the file http://localhost/association/belongsto.js (http://localhost/association/belongsto.js?_dc=1350299721164).
I get the error [Ext.Loader] Failed loading 'association/belongsto.js', please verify that the file exists from all-classes.js

I created a simple example where I just add a model to the generated app using:
sencha generate app MyApp /path/to/MyApp

In Main.js I just add this line:

models: ['WebDialog']

And then create the file MyApp/app/model/Dialog.js.

Ext.define('MyApp.model.Dialog', {
// require: 'MyApp.model.Row', // Skipping require to avoid need of that file in this example code
{name:'id', type:'int'}

model:'MyApp.model.Row', // Row model doesn't exist, but that is not relevant for this issue

Running sencha app build will result in an application that generates the following errors:
Uncaught Error: [Ext.Loader] Failed loading 'association/hasmany.js', please verify that the file exists all-classes.js:1 (file:///D:/temp/testapp/build/testapp/all-classes.js)
Uncaught Error: [Ext.Loader] Failed loading 'MyApp/model/Dialog.js', please verify that the file exists

Looking at the all-classes.js I see that it's correct that the hasmany code hasn't been added. I tried adding an explict requires in the app.js to just force the inclusion of this code and it is then added but it doesn't remove the problem.

What can I do to get around this problem?

Versions used:
ExtJS 4.1.2a
Sencha Command v3.0.0.190.

15 Oct 2012, 7:26 AM

I have the same problem here. The behavior is the same with Sencha Cmd

16 Oct 2012, 7:02 AM
I found a workaround

I added the require directive in the index.html file

<!-- <x-compile> -->
<!-- <x-bootstrap> -->
<script src="ext/ext.js"></script>
<script src="bootstrap.js"></script>
<!-- </x-bootstrap> -->
<script type="text/javascript">
//@require Ext.data.association.*
<script src="app/app.js"></script>
<!-- </x-compile> -->

But I think this is a real bug that need to be fix.

17 Oct 2012, 6:45 AM
Your model should use the requires array to require the association it needs.

17 Oct 2012, 7:06 AM
Thanks It's working. I don't know why I did not figure this by myself....

17 Oct 2012, 3:34 PM
Not working for me, what else could be ?
I had require in the model

hasMany : [{model: 'MyApp.model.MyList', name: 'offices', autoload : true },

Uncaught Error: [Ext.Loader] Failed loading 'Cars/model/MyList.js', please verify that the file exists all-classes.js:10092 (http://localhost:8181/wam/all-classes.js)

Uncaught Error: [Ext.Loader] Failed loading 'association/belongsto.js', please verify that the file exists

17 Oct 2012, 3:42 PM
I added the require that way

Ext.define('NL.model.TemplateChannel', {
requires: ['Ext.data.association.BelongsTo'],
extend: 'Ext.data.Model',
fields: [
associations: [{
type: 'belongsTo',
model: 'NL.model.AdminChannel'

Same thing for HasMany

17 Oct 2012, 4:26 PM
Thanks for your Reply!!

I am getting compilation error when i changed it to associations

associations: [
{ type: 'hasMany', model: 'MyApp.model.MyBranchList', name: 'branches', autoload : true }

Please help!!

17 Oct 2012, 4:39 PM
it works.it was a syntax errror
Now some other problem....let me take a look :) Thanks

12 Dec 2013, 1:32 AM
I had the same problem. I had to put require 'Ext.data.association.*' inside main application class to make it work.