You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
autoFetch does't work when cache is true for a model #339
In this example Reward has one to many relationships with RewardType when cache is left default (true) Reward.get(...) returns undefined for property "type" while type_id has a value.
When setting cache: false to both models, the 'type' property gets populated as expected using autofetch.
Is this a bug or is it normal behaviour? Spend hours trying to figure why autoFetch wasn't working...
cache is something hard to do in this situations, but we still have some work to do on this. What cache means on ORM is Singleton pattern, meaning: when fetching a record that was previously fetched (it uses table+ids to know that), return the same JS object instance.
This behaviour is seen when you fetch the same record more than one time and keep references to them. They will be the same JS object which means that if you change a property, all references change (because they are one).
On associations this is still not working properly. The code is somehow "caching" certain records when it doesn't have all data and then when you look for the record (using .find()) it uses the bad cached item. We have to track and solve this.
I would suggest, until you are able to resolve the problem with caching and associations, to have cache: false by default as opposed being true that it is now.
It would save people from a lot of confusion (on why autoFetch doesn't work primarily)
Seems like this is related to #490. I have this problem in versions 2.1.13 to 2.1.19. I have played around with caching settings, but after reading a variety of tickets I will try looking into that deeper today.
Activity
dresende commentedon Sep 16, 2013
cacheis something hard to do in this situations, but we still have some work to do on this. Whatcachemeans on ORM is Singleton pattern, meaning: when fetching a record that was previously fetched (it uses table+ids to know that), return the same JS object instance.This behaviour is seen when you fetch the same record more than one time and keep references to them. They will be the same JS object which means that if you change a property, all references change (because they are one).
On associations this is still not working properly. The code is somehow "caching" certain records when it doesn't have all data and then when you look for the record (using
.find()) it uses the bad cached item. We have to track and solve this.mkMoSs commentedon Sep 16, 2013
To give more details on how it happens here's the full code
As you might notice, I drop everything and recreate them again initially.
Outputting to console the fetched reward in the end gives:
typeis undefined which is the problem. After turning off cache in the models:works as expected
mkMoSs commentedon Sep 16, 2013
I would suggest, until you are able to resolve the problem with caching and associations, to have
cache: falseby default as opposed being true that it is now.It would save people from a lot of confusion (on why autoFetch doesn't work primarily)
dresende commentedon Sep 18, 2013
I don't want to change the default behaviour for now. I think I found the problem behind this. I'm fixing this for each association type.
Fixes cache for hasOne associations (#339)
dresende commentedon Sep 21, 2013
If it doesn't work (the latest commit), please reopen.
twk-b commentedon Sep 22, 2014
Seems like this is related to #490. I have this problem in versions 2.1.13 to 2.1.19. I have played around with caching settings, but after reading a variety of tickets I will try looking into that deeper today.
iceNuts commentedon Oct 25, 2015
Hi there,
I am wondering what is the best solution yet, I have the same problem and it has been a year, hope there is some official way to do this.
Thanks.