View Full Version : Using hasOne association

23 Dec 2011, 9:10 AM

I'm having a hard time with the hasOne association. The generated getter always tries to load data through its proxy but the parent model already has the needed data.

I have a Club model and an Address model.


Ext.define('My.model.Club', {
extend: 'Ext.data.Model',

fields: [

proxy: {
type: 'rest',
url: '/clubs',
reader: {
type: 'json',
root: 'clubs'

associations: [{
type: 'hasOne',
model: 'My.model.Address',
getterName: 'getAddress',
setterName: 'setAddress',
foreignKey: 'address_id'


Ext.define('My.model.Address', {
extend: 'Ext.data.Model',

fields: [

proxy: {
type: 'rest',
url: '/addresses',
reader: {
type: 'json',
root: 'addresses'


Loading data like so

var club = Ext.ModelMgr.getModel('My.model.Club');
club.load(1, {
success: function (c, o) {

loads the data for a club with the id 1 using the proxy defined in Club.js. The data looks like this:

"success": true,
"clubs": [{
"id": 1,
"name": "Club name",
"email": "info@example.com",
"phone": "+41811234567",
"membersince": "2011-12-16",
"address_id": 1,
"address": {
"id": 1,
"street": "Teststreet",
"zip": "1234",
"city": "Testcity",
"country": "CH"

How can I prevent c.getAddress() from triying to load address data again? I only want getAddress() to load the address data, if it can't be found within the returned data.

Thank you for helping me out on this.

27 Dec 2011, 3:28 AM

10 Feb 2012, 7:55 AM

Again; associations and the use of them in components are NOT documented at all.
Now that 4.1 has a hasOne it is clear that the associations have been implemented without thinking.

next to that there just seems no communications between the different developers, the combo box (which is very important) raises so many questions that it seems one made the combo and somebody else made the data package.

Questions like this are sparsely answered because nobody seems to know it so if not some developer is taking the time, no answer from the community.

Sencha's products are better than nothing (or others), but as a very experienced developer Sencha products make me experiment to get things work. In all figuring out these things cost me 90% of my time.

I had the feeling we were missing a hasOne, but since the associations are not supported by any of the components I never got anything to work with them. Writing plugins is extremely hard and with every new version they stop working. Extjs 4 has been on the market for about a year, and it is still missing important parts.

Reading the forums the Sencha developer at least seem to answer, but in such a way that if your situation is somewhat different, the answer is completely useless most of the time.

Within the forums people loose their temper, others respond with "hey you should act like an adult".
I can understand both. When you contact management about this, you get very bad discussions.

Yes I'm a paying customer (I work for one), yes I feel that Sencha has "Senior" developers which in my eyes do not earn that title and has "Senior" developers which are not used as architects.

I know 4.1 is still in beta, 4.0 has not been finished an still technically in beta too!!! this is not something I say just to hurt Sencha, I say this because it is my experience and Sencha's products continue to hurt us.

the Docs have been improved from version 3, the are a little more examples. but what is missing: Try to know nothing about models, stores, asociations and you'll find out it just is not there, Api Docs should be accompanied by examples. but also by a technology document. the guides are nice to sell Sencha but as a user of the product, it is useless crap, period!!!!!!

Questions like this should not be in the forums and answeres should not point to another tread, it should point to the proper documentation, since I almost never see that, I see that as proof for the documentation not being in proper order.

Dear Sencha, please do know that we are not all able to cross the ocean and attend your conferences, please do know that professionals need professional documentation. Please do know I have been working with your products since version 2, and please do know people get frustrated by trying and trying and trying and searching and searching and searching for things that should be covered by documents that explain HOW things work, how things are used in conjunction with each other.

If you do so, you'll get happier customers, less forum questions and more exposure and so more business.
When I try to find websites using Extjs, I just do not seem to find one. It might be used for Internal only systems, I do not know. Here people have left their job because they were sick of Extjs and did not want to work with it.


(yes, I need to shout here since I have tried nicely before with little or no effect).

With 4.1 you can make a difference, take that chance, please, I will not cost you a single dime extra and save you and your customers HUGE amounts of time and frustration.

we have renamed (as a painful joke) Extjs to: Extremely frustrating Javasrcipt.

11 Feb 2012, 1:18 PM
did you try setting associationKey ?
with associationKey doing a getMyStuff() will know where to read the data.