Discussion:
[Modeling-users] One to Many Relationships
Kertis, Dennis
2004-08-18 04:03:02 UTC
Permalink
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>
Sebastien Bigaret
2004-08-18 07:45:11 UTC
Permalink
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
Post by Kertis, Dennis
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.
Post by Kertis, Dennis
I am trying to define a one-to-many relationship in XML. However,
Object: Relationship Category.topics
------------------------------------
- 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>
Kertis, Dennis
2004-08-18 11:04:04 UTC
Permalink
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
name='topics'
destinationEntity='Topic'
deleteRule='2'
multiplicityLowerBound='0'
multiplicityUpperBound='*'
thanks,
Dennis





-----Original Message-----
From: Sebastien Bigaret [mailto:***@users.sourceforge.net]
Sent: Wednesday, August 18, 2004 5:45 AM
To: Kertis, Dennis
Cc: modeling-***@lists.sourceforge.net
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='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
Post by Kertis, Dennis
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.
Post by Kertis, Dennis
I am trying to define a one-to-many relationship in XML. However,
Object: Relationship Category.topics
------------------------------------
- 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>
Sebastien Bigaret
2004-08-18 12:58:15 UTC
Permalink
Post by Kertis, Dennis
Serious: couldn't load the model
exceptions.ValueError
invalid literal for int(): *
<relation
name='topics'
destinationEntity='Topic'
deleteRule='2'
multiplicityLowerBound='0'
multiplicityUpperBound='*'
thanks,
Dennis
That's definitely a bug. Try '-1' instead of '*'! Thanks for reporting.

-- Sébastien.

Loading...