when a model has more than association of the same type to the same associated model type.
like person has one father(Person) and person has one mother(Person)
- Model.instanceName Collision
instanceName is the property that holds the associated model instance (source code of data/associations/ hasOne and belongsTo)
its calculated using instanceName: associatedName + 'BelongsToInstance' (or 'HasOneInstance')
associatedName its the associated model type (as a string)
really any test is not needed to know Person+'BelongsToInstance' will collide when you have more than one association to Person.
btw associatedName cannot be set to a random string , it needs to be the associated model type.
i implemed a fix that let user set a name property to the relationtion, pretty much as hasMany does,
name is a random string that diferentiates the association so instanceName can be calculated as
instanceName = name + 'BelongsToInstance' (or 'HasOneInstance')
associations already have a name property is just instanceName formula in belongsTo and hasOne doesnt use it.
hasMany uses name property to define the storeName wich is analog to instanceName, so having many hasMany association to the same model will never collide.
- Inverse association calculation error
belongsTo and hasMany tries to figure the inverse association after loading record with nested data
using (on their respective read method source code)
this will lead to problems having more than 1 association of the same type.
there can be more than one association with same association type + associated model type (current formula)
its not implemented in belongsTo because with that formula you cant figure if the inverse is hasMany or HasOne
to get inverse association with precision needs model name + foreign key
there wont be more than one association using the same model name with the same foreign key.
this also serves for all associations, including belongsTo will figure if the inverse is hasMany or hasOne.
in a own fix i just put this in the Ext.model.association so all associations can ask for their inverse.
both of them really doesnt need test cases, but to test collision just build a model with 2 relations to the same type
load the first associated record then load second one, when loading the second one ull always get the first and with errors
loading the father no problem.
loading the mother will return the already loaded father, since theres only 1 instanceName so getter thinks its already loaded,
because he uses instanceName to figure if a record its been loaded.
and to check the inverse association is a bit harder, because Extjs only does this depending on wind direction and moon state.
"only happens in some cases when you load a record and the loaded record must come with associated data,
also only happens in hasOne and hasMany because belongsTo doesnt has this implementation, and cannot be more than one association to the same model."
i think this is bad design it should be something like
"When you associate two records Extjs will establish association in both direcctions"
atm Extjs doesnt supports more than one relationship of the same type to the same model. dont know if it was designed like that , but every other technology that let usdefine data association allows it and all databases, and anyway the fixs are so small to let Extjs do this, if it not a feature then in docs should say
"you cant define more than one relationship to .. or ull get errors"