Discussion:
[Modeling-users] possible bug with autorelationships
Lorenzo Gil Sanchez
2004-09-17 10:20:12 UTC
Permalink
Hi,

I have a Person entity and I'm trying to define a relationship between
two persons. Something like the husband/wife relationship. So far it
works, the problem is when other classes appear in the inheritance tree.

I have a Customer entity which is-a Person, which is-a BaseType. This is
how my PyModel looks like:

from Modeling.PyModel import *

Entity.defaults['properties'] = [
APrimaryKey('id', isClassProperty=0, isRequired=1, doc='PK')
]

_connDict = {'database': 'pruebas_modeling.sqlite'}

model = Model('Pruebas', adaptorName='SQLite', connDict=_connDict,
version='0.1')

model.entities = [
Entity('BaseType',
properties=[AFloat('oid', doc='Internal object identifier')]
),

Entity('Person',
properties=[AString('name'),
AString('surname'),
ADateTime('birthdate'),
AInteger('employed', defaultValue=1),
RToOne('husband', destination='Person',
inverse='wife'),
RToOne('wife', destination='Person',
inverse='husband')],
parent='BaseType',
),
Entity('Customer',
properties=[AFloat('salary')],
parent='Person',
),
]

model.build()

------------------------------------------------------

If I run that code I get this exception:
Traceback (most recent call last):
File "prueba_autorrelacion.py", line 32, in ?
model.build()
File "/opt/lib/python2.3/site-packages/Modeling/PyModel.py", line 228,
in build
entity.build_toOne_relationships(self)
File "/opt/lib/python2.3/site-packages/Modeling/PyModel.py", line 446,
in build_toOne_relationships
prop.build(model, self)
File "/opt/lib/python2.3/site-packages/Modeling/PyModel.py", line 701,
in build
entity.forward_rel_info(self, model)
File "/opt/lib/python2.3/site-packages/Modeling/PyModel.py", line 437,
in forward_rel_info
rel.dst,invr.src=check_or_make_equal(rel.dst,invr.src)
File "/opt/lib/python2.3/site-packages/Modeling/PyModel.py", line 421,
in check_or_make_equal
assert x == y
AssertionError


There are several ways to get rid of the exception:

- Remove the Customer entity
- Make the Person entity don't inherit from BaseType
- Remove the BaseType entity

Obviously none of those is what I want so I wonder if anyone in the list
knows why my relations are messing the inheritance or viceversa.

Thanks

Lorenzo Gil Sanchez
Sebastien Bigaret
2004-09-21 08:20:27 UTC
Permalink
Hi,

Sorry for the late answer.

You've found a bug, indeed; however, it's not exactly where we think it
can be at first sight!

The fact is that we do not support one-to-one relationship directly
for the moment being, see here the instructions for a workaround:
http://modeling.sourceforge.net/UserGuide/design-rels.html

The error you get is completely due to the fact that a one-to-one isn't
expected there, but this should be treated by something else than an
assert clause.

I've not look closely yet to what happens when you suppress the BaseType
(hence, suppressing the error as well), but I suspect that the model is
not correct. This needs further investigation, obviously --in any case,
again, the pymodel should be able to report that the one-to-one is not
supported yet.

Thanks for reporting,

-- Sébastien.
Post by Lorenzo Gil Sanchez
Hi,
I have a Person entity and I'm trying to define a relationship between
two persons. Something like the husband/wife relationship. So far it
works, the problem is when other classes appear in the inheritance tree.
I have a Customer entity which is-a Person, which is-a BaseType. This is
from Modeling.PyModel import *
Entity.defaults['properties'] = [
APrimaryKey('id', isClassProperty=0, isRequired=1, doc='PK')
]
_connDict = {'database': 'pruebas_modeling.sqlite'}
model = Model('Pruebas', adaptorName='SQLite', connDict=_connDict,
version='0.1')
model.entities = [
Entity('BaseType',
properties=[AFloat('oid', doc='Internal object identifier')]
),
Entity('Person',
properties=[AString('name'),
AString('surname'),
ADateTime('birthdate'),
AInteger('employed', defaultValue=1),
RToOne('husband', destination='Person',
inverse='wife'),
RToOne('wife', destination='Person',
inverse='husband')],
parent='BaseType',
),
Entity('Customer',
properties=[AFloat('salary')],
parent='Person',
),
]
model.build()
------------------------------------------------------
File "prueba_autorrelacion.py", line 32, in ?
model.build()
File "/opt/lib/python2.3/site-packages/Modeling/PyModel.py", line 228,
in build
entity.build_toOne_relationships(self)
File "/opt/lib/python2.3/site-packages/Modeling/PyModel.py", line 446,
in build_toOne_relationships
prop.build(model, self)
File "/opt/lib/python2.3/site-packages/Modeling/PyModel.py", line 701,
in build
entity.forward_rel_info(self, model)
File "/opt/lib/python2.3/site-packages/Modeling/PyModel.py", line 437,
in forward_rel_info
rel.dst,invr.src=check_or_make_equal(rel.dst,invr.src)
File "/opt/lib/python2.3/site-packages/Modeling/PyModel.py", line 421,
in check_or_make_equal
assert x == y
AssertionError
- Remove the Customer entity
- Make the Person entity don't inherit from BaseType
- Remove the BaseType entity
Obviously none of those is what I want so I wonder if anyone in the list
knows why my relations are messing the inheritance or viceversa.
Thanks
Lorenzo Gil Sanchez
Loading...