View Full Version : HasOne , why ?

13 Aug 2012, 10:14 PM
How can we use HasOne association ?

I explain :
If i have a model which own one (or more) HasMany associations, when i load a full object, these associations are transform in store with zero, one or more records.
But if i have a HasOne association... If my object have one, there's no problem, but if there's no object, this association is not initialized
So, when i try to call myObjet.GetMyAssociation() there's a ajax call to retrieve this object.
So i MUST include idForeign in my object, and even if it's null, there's a call

Why ? what is he purpose of the HasOne Association ? is it only a "helper" ?

14 Aug 2012, 12:48 PM
To set a 1 to 1 relationship between models ...

Per the API, the getter is always called.
You can use the callback to determine the result, but there will be a call.


24 Feb 2016, 3:01 PM
There is no practical reason for the hasOne relationship. I just ended up using the hasMany and used myAssociationStore.getAt(0) to get the hasOne record.