PDA

View Full Version : Stop HasOne Associations from Auto Hitting Server?



jakejamessteele
26 Feb 2014, 5:20 PM
I am currently loading large nested models, when a model is new it looks something like:



{
"data": {
"id": 2,
"effectiveDate": new Date(
1392192000000
),
"terminationDate": new Date(
1392883200000
),
"Division": null,
"budgets": [],
"saleGoals": [],
"teamMembers": []
},
"total": 1,
"success": true
}


When it processes that information into the forms it checks the division for a: record.getDivision().getUser() (association)
it tries to hit the server twice once for the division and once for the user. The issue is that without any id's it just hits my server requesting, a full list of divisions and a full list of users, and then throws an error.

What would be ideal is that the associations would just stay local, I already check to see if the id is 0 on the record (extjs auto creates a blank Division with a blank User in the associated store) but when I call the getDivision().get('id') == 0 it hits the server for the division.

How do I stop the association from auto hitting the server when I don't have data for that association yet?

jakejamessteele
28 Feb 2014, 10:31 AM
bump :D

mitchellsimoens
3 Mar 2014, 7:25 AM
If the association isn't given data, it will attempt to retrieve the data. Only way to stop it currently is to override the association or give it dummy data.

jakejamessteele
3 Mar 2014, 9:29 AM
If I pass it in a empty record with a zero based id, will the association still think its a proper record or does a zero based id mean phantom and it will hit the server again anyway? I am worried it will attempt a PUT call at some point if I give it a real id.