RE: [Modeling-users] One to Many Relationships
Status: Abandoned
Brought to you by:
sbigaret
From: Kertis, D. <dk...@vo...> - 2004-08-18 13:03:05
|
Actually, I had that in my model but got this error: Serious: couldn't load the model exceptions.ValueError invalid literal for int(): * Here is the code: <relation=20 name=3D'topics' destinationEntity=3D'Topic' deleteRule=3D'2' multiplicityLowerBound=3D'0' multiplicityUpperBound=3D'*' thanks, Dennis -----Original Message----- From: Sebastien Bigaret [mailto:sbi...@us...]=20 Sent: Wednesday, August 18, 2004 5:45 AM To: Kertis, Dennis Cc: mod...@li... Subject: Re: [Modeling-users] One to Many Relationships Hi Dennis, The problem is that you forgot to indicate in your model that it is a to-many relationship, so the script reacts as if it was a to-one relationship. See section 2.5.5. in the User's Guide; a unbound = to-many relationship typically defines: multiplicityLowerBound=3D'0' multiplicityUpperBound=3D'*' (in your case you got the default values, i.e. respectively '0' and=20 '1', defining a to-one relationship) Please also note that there is currently nothing in the framework that makes sure that your XML-models does not rely on defaults that have changed between two releases (this is not the case for PyModels, which defines a 'version' field for this very purpose, see section 2.4.4). The reason why there is no such mechanism is that the xml model is not supposed to rely on defaults... even if I fear that this is not said at all in the User's Guide. It does NOT mean you should always specify every possible fields in your xml model: it just means that you should be careful. When in = doubt, you can easily have your model dumped in another xml model with all its value defined: >>> from Modeling.Model import loadModel >>> model=3DloadModel('your_model.xml') >>> model.saveModelAsXMLFile('FULLY_QUALIFIED_MODEL.xml') Just a little warning: be sure to give an other filename, or you'll overwrite your own model! -- S=E9bastien. Kertis, Dennis wrote: > I am trying to define a one-to-many relationship in XML. However, > I am getting the following error: >=20 > Object: Relationship Category.topics > ------------------------------------ > * Error(s): > - relationship is not mandatory but source attribute Category.id > is required > > Can anyone tell me the correct way to model a one-to-many with = Modeling? > My "many" table has a foreign key to the primary key of my "one" = table, > but modeling doesn't seem to like this. > > Below is a cutdown of my model. >=20 > <entity > name=3D'Topic'> > <primaryKey attributeName=3D'id'/> > <attribute=20 > name=3D'id' > type=3D'int' > isRequired=3D'1'/> > <attribute=20 > name=3D'categoryID' > type=3D'int' > isRequired=3D'1'/> > </entity> > <entity > name=3D'Category' > <primaryKey attributeName=3D'id'/> > <attribute=20 > name=3D'id' > type=3D'int' > isClassProperty=3D'0'=20 > isRequired=3D'1'/> > <relation=20 > name=3D'topics' > destinationEntity=3D'Topic'> > <join=20 > sourceAttribute=3D'id' > destinationAttribute=3D'categoryID'/> > </relation> > </entity> |