View Full Version : How to get parent model ?

14 Mar 2012, 9:36 PM
1. is it possible to get the parent model (in a hasMany relationship) if the parent model does not have an ID yet (has not been saved to server)?

2. is it possible to get the parent model without declaring a belongsTo relationship? The relationship is there, the child is in a store that belongs to the parent. Can I get a reference to the parent without the belongsTo relationship?


14 Mar 2012, 11:52 PM
why not defining the belongsTo association ?
life could be much easier for you ;D
the "inverse" pointer from the associated record to the host record is only set if you declare the association.
also only if you load the asociated record :D
also the inverse pointer has some bugs.
best option is for question #1 you already have the pointer to the parent model (as is not saved, exists in the client side), find a way to work with it not using the associated model.

for second question, i guess the parent model is saved, or the both questions could be the same, and since theres no belongsTo you can load it manually. using the foreign key. also if you already have the parent model loaded, well just use that pointer because the child record wont have any pointer to the parent.

24 May 2012, 5:48 PM