Re: [Modeling-users] One to Many Relationships
Status: Abandoned
Brought to you by:
sbigaret
From: Sebastien B. <sbi...@us...> - 2004-08-18 09:44:45
|
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='0' multiplicityUpperBound='*' (in your case you got the default values, i.e. respectively '0' and '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=loadModel('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ébastien. Kertis, Dennis wrote: > I am trying to define a one-to-many relationship in XML. However, > I am getting the following error: > > 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. > > <entity > name='Topic'> > <primaryKey attributeName='id'/> > <attribute > name='id' > type='int' > isRequired='1'/> > <attribute > name='categoryID' > type='int' > isRequired='1'/> > </entity> > <entity > name='Category' > <primaryKey attributeName='id'/> > <attribute > name='id' > type='int' > isClassProperty='0' > isRequired='1'/> > <relation > name='topics' > destinationEntity='Topic'> > <join > sourceAttribute='id' > destinationAttribute='categoryID'/> > </relation> > </entity> |