[baseten-users] to-many relationship defined but not seen, bug?

Jianhua Meng jh_meng at mac.com
Tue Apr 14 18:56:20 EEST 2009


Thanks Tuukka for your tips. The explanation makes sense. I figured  
out the root cause of our problem. For all the to-many relationships  
we have been using a consistent naming convention, i.e.  
destinationEntitys, e.g. insurancePlans and contacts. We have written  
a custom method to translate the more natural name to the less natrual  
name DestinationEntitys. Notice the 's' at the end of all the to-many  
relationships. Well, insurancePolicies, while natural and of good  
English form, deviates from the pattern. It would work if we renamed  
the relationship to insurancePolicys. Anyway, we can work around this  
problem now that we understand the cause.

On Apr 14, 2009, at 7:30 AM, Tuukka Norri wrote:

> Hi!
>
> Jianhua Meng kirjoitti 11.4.2009 kello 22.52:
>> I don't know if this is a bug in the baseten framework or a bug on  
>> my part. For some reason I could not figure out, a to-many  
>> relationship in our app does not appear to be available when it is  
>> clearly defined in the model along with many other similar  
>> relationships.
>>
>> We have, in the model of interest, InsuranceCompany --(x)-->>  
>> InsurancePlan --(y)-->> InsurancePolicy, where x and y are both to- 
>> many relationships. x works fine and y does not. When y is  
>> accessed, it triggers the following error:
>>
>> BXDatabaseObject.m:540  -[BXDatabaseObject primitiveValueForKey:]  
>> [0x40d640m] 	  ERROR: Key insurancePolicies wasn't found in entity <pgsql://Wuxing.local.:5432/quickceph InsurancePlan (0x159663a0) validated: 1 enabled: 1 
>> >. (Called from an instance of QCXInsurancePlan.)
>> 2009-04-11 11:28:43.996 QuickCephOffice[23939:813]  
>> [<QCXInsurancePlan 0x159d25f0> valueForUndefinedKey:]: this class  
>> is not key value coding-compliant for the key insurancePolicies.
> Unfortunately not all names defined in the data model can be given  
> to relationships. We use the foreign key's name on the to-one side,  
> but on to-many-side the relationship is named  
> “schema_table_foreignkey”. Since insurancePolicy is the only  
> relationship in InsurancePlan that has InsurancePolicy as its  
> target, you can also use the name “InsurancePolicy”. To us it seemed  
> that using the target table's or view's name is the simplest  
> alternative, even though it doesn't correspond to what is defined in  
> the Xcode data model. (See sections 2.2.1 and 2.2.2 in the manual.)
>
>> From our point of view, the QCXInsurancePlan.insurancePolicies  
>> appears to be defined properly in the model and in our code. What  
>> then can explain for the error message? How should I go about  
>> debugging this? I poked around the entity descriptions of  
>> QCXInsurancePlan, and could not figure out how to interpret the  
>> results. I expected to see all the relationships to be described  
>> there or somewhere, but I could not find explicit evidence.
> BXRelationshipDescription's -description method doesn't currently  
> show whether the relationship references one or many objects. You  
> can use -isToMany to determine this but an easier way is to build  
> and run the Introspection tool in Examples directory. (If you're  
> using SVN trunk, it won't work right now, but the tool also exists  
> in tags/1.6.2.)
>
>> How does an entity report a to-many relationship? How do I know if  
>> a to-many relationship is defined according to the underlying  
>> BXEntityDescription? I don't see an explicit entry for  
>> 'insurancePolicies' in the reported results. But on the other hand,  
>> I don't see the expected 'insurancePlans' in InsuranceCompany's  
>> relationshipsByName report either. The latter is known to work as  
>> expected.
>> (gdb) po [entity relationshipsByName]  // where entity is extracted  
>> from an instance of QCXInsurancePlan
>> {
>>    InsuranceCompany = <BXRelationshipDescription (0x165684d0) name:  
>> InsuranceCompany entity: InsurancePlan destinationEntity:  
>> InsuranceCompany>;
>>    InsurancePolicy = <BXRelationshipDescription (0x16568350) name:  
>> InsurancePolicy entity: InsurancePlan destinationEntity:  
>> InsurancePolicy>;
>>    "PracticeManagement_InsurancePolicy_insurancePlan" =  
>> <BXRelationshipDescription (0x16568010) name:  
>> PracticeManagement_InsurancePolicy_insurancePlan entity:  
>> InsurancePlan destinationEntity: InsurancePolicy>;
>>    insuranceCompany = <BXRelationshipDescription (0x16568400) name:  
>> insuranceCompany entity: InsurancePlan destinationEntity:  
>> InsuranceCompany>;
>> }
>> ...
>> (gdb) po [[company entity] relationshipsByName] // where company is  
>> an instance of QCXInsuranceCompany
>> {
>>    AdjustedFee = <BXRelationshipDescription (0x1658b0f0) name:  
>> AdjustedFee entity: InsuranceCompany destinationEntity: AdjustedFee>;
>>    InsurancePlan = <BXRelationshipDescription (0x1658af30) name:  
>> InsurancePlan entity: InsuranceCompany destinationEntity:  
>> InsurancePlan>;
>>    "PracticeManagement_AdjustedFee_insuranceCompany" =  
>> <BXRelationshipDescription (0x1658b020) name:  
>> PracticeManagement_AdjustedFee_insuranceCompany entity:  
>> InsuranceCompany destinationEntity: AdjustedFee>;
>>    "PracticeManagement_InsurancePlan_insuranceCompany" =  
>> <BXRelationshipDescription (0x1658ae80) name:  
>> PracticeManagement_InsurancePlan_insuranceCompany entity:  
>> InsuranceCompany destinationEntity: InsurancePlan>;
>> }
> I can't say for sure why insurancePlans works (it shouldn't). On the  
> other hand, a relationship named “InsurancePlan” exists and should  
> work. All relationships should get listed by -relationshipsByName,  
> since that's what -[BXDatabaseObject primitiveValueForKey:] uses.
> -- 
> Best regards,
> Tuukka Norri
> MK&C
>
> _______________________________________________
> baseten-users mailing list
> baseten-users at lists.basetenframework.org
> http://lists.basetenframework.org/mailman/listinfo/baseten-users

Regards,
Jianhua Meng









More information about the baseten-users mailing list