PDA

View Full Version : Association on loaded model fails



pfried
17 Oct 2012, 7:41 AM
I will give it a new try, as long as nobody has answered.

I Posted a Quote from the Sencha Touch Docs Associations Topic unter the topic

I trie to do the following:
I create a User by passing credentials to a server which authorizes the request and sends back the user if the request succeeds. The User is created and i want to store configurations for the app (could be several).

I create a Configuration Model and give it a localstorage proxy.

I associate the User with the configurations by a hasMany Association.I trie to load the User's configurations by User.configurations() , the problem is this store contains all the configurations for every user, i guess there is a problem with the filter.

I made an Example for this problem: http://www.senchafiddle.com/#4FIt7

pfried
17 Oct 2012, 10:12 PM
Hey guys,
i was a little bit confused and frustrated yesterday. Maybe thats why i posted in the wrong place.

But to make my problem clear:

I thought if i set up an association and call the association by Instance.associations() i get a new store containing the instances from the proxy which are bound to the foreign key by "x_id".

But the store i call by Instance.associations() contains all the instances from the associated proxy.

It set up an example: www.senchafiddle.com/#4FIt7 (http://www.senchafiddle.com/#4FIt7)

I am new to Sencha touch, maybe i am just missing the point.

Thank you!

pfried
18 Oct 2012, 12:14 AM
The new Store is only instantiated the first time you call products() to conserve memory and processing time, though calling products() a second time returns the same store instance.Custom filteringThe Store is automatically furnished with a filter - by default this filter tells the store to only return records where the associated model's foreign key matches the owner model's primary key. For example, if a User with ID = 100 hasMany Products, the filter loads only Products with user_id == 100.

pfried
18 Oct 2012, 8:00 AM
The post above is a quote from the docs

hello there,

i tried to get closer to the problem, but i think i really need help here. The problem looks like a bug to me although i know i am a beginner in sencha touch.

I think that the filters arent applied correctly to the store, because it's containing every instance that belongs to the model. Is this a bug? I have accessed the instances by .first() and .getAt(0)

please help me

pfried
19 Oct 2012, 4:05 AM
hey,

i tried to solve the problem, but i am going through endless debuggings wondering why the filter doesnt work properly. The store which is instantiated on call of the associations has a filter which is is alright but it seems to me that this store contains instances from the proxy of the model which do NOT match the filter!

Can somebody review my problem please? I am wasting my time i guess

pfried
21 Oct 2012, 10:21 PM
my problem is still unsolved. I posted this in the docs and on stackoverflow. Is there anybody who could take a closer look to this?

pfried
23 Oct 2012, 4:08 AM
I figured out that if i load a instance from the localstorage the proxy breaks the association or the filter. Without a proxy the associated model is loaded right.

Without localstorage proxy : http://www.senchafiddle.com/#J9VX6

With localstorage proxy : http://www.senchafiddle.com/#J9VX6#hBDkq

Without saving it to the localstore everything works, if i want to use a proxy the association is not working anymore. Why is this ? I found no hint that it is not possible to store associations and load them later.

I have a guess why this is not working, sencha tries to translate the ids into internal ids, maybe this is breaking up the pair of id / internalId ?

pfried
23 Oct 2012, 11:28 AM
i am stuck with this problem since a week now and i dont know how to solve this.

I am asking why nobody can help me with this issue. Is it because nobody has a clue how to do this or is it because it is not detailed enough?

If it was simply a beginners fault, i guess somebody would have posted an answer even if the solution was obvious.

At this point i would like to ask somebody at Sencha to take a look at this.

pfried
25 Oct 2012, 11:51 PM
i would still be interested in a solution for this. Or simply reply to this thread, i would be happy with that too :">

sdruckerfig
28 Oct 2012, 6:21 AM
I think that your solution is to stop using Associations - particularly if LocalStorage is involved.

Models do allow you to store abstract data types, although this feature is not particularly well documented.

Something like the following should work:


Ext.define("MyApp.model.Pref", {
extend: 'Ext.data.Model',
config: {
fields: [
'field1','field2'
],

proxy: {
type: 'localstorage',
id: 'tester'
}
}

});


var myModel = Ext.create("MyApp.model.Pref", {
field1: 'Steve Drucker',
field2: {
pref1: 'a',
pref2: 'b'
}
});

myModel.save();

pfried
29 Oct 2012, 12:15 AM
hey, i really appreciate your help and it pointed me another way to solve it. I figured out some ways to workaround the problem.

I am evaluating Sencha Touch beside others. I am creating a demo application with some defined features. It would have been nice if it was possible to use the association, its a cool feature although not working. I solved this by using a foreign key (uuid to ensure unique).

Maybe we are going to buy support as we like sencha touch.

Möhre
30 Oct 2012, 3:52 AM
Association bugs and problems are still unsolved:
http://www.sencha.com/forum/showthread.php?173327-WebStorage-proxy-can-t-deal-with-associated-data

I guess that buying support will not solve these bugs.

pfried
31 Oct 2012, 12:19 AM
Thank you very much for the link, this really answers my question.