Discussion:
[Modeling-users] Many-to-many relationship example doesn't work?
c***@satnet.lt
2004-08-10 10:55:03 UTC
Permalink
Hello,

First of all thanks to Sabastien for his efforts creating this framework.
Projects I'm involved now requires lots of Many-To-Many relations in E-R
model, so I've tried adding methods (for tranparent access to correlation
entity) as described in the example in UsersGuide 2.6.3. But those methods
doesn't work. So I've copy-pasted example from user's guide, but it did'nt
work as well.:
i.e I add methods getAddresses(), addToAddresses()
to the class "Person", Then I try to run a code, that uses those classes:
-------------
#test.py
from Modeling.EditingContext import EditingContext
from MM1 import Person, Address
ec=EditingContext()
p = Person.Person()
a = Address.Address()
p.addToAddresses(a)
ec.insert(p)
ec.insert(a)
ec.saveChanges()
-----------------
I get an error:
Traceback (most recent call last):
File "./test.py", line 8, in ?
p.addToAddresses(a)
File "/tmp/test2/MM1/Person.py", line 76, in addToAddresses
self.editingContext().insert(_pa)
AttributeError: 'NoneType' object has no attribute 'insert'
-----------------
I've looked into CustomObject.py, and i could'nt find any assigment of
REAL editing, context, only initial definition 'lambda self: None'
Did i misunderstood something, or this example code in User's guide is
just out-dated?

Can someone please give me some guidlines?

I'm using: Python 2.3, Modeling: 0.9-pre-17.1
Ernesto Revilla
2004-08-10 14:11:07 UTC
Permalink
Hi,

You have to add the instance to both sides of the relation, the
a.setPerson(p)

is missing.

To add an instance to both sides of a relation, you can do also:

p.addObjectToBothSidesOfRelationshipWithKey(a, ’addresses’)

Erny
Post by c***@satnet.lt
Hello,
First of all thanks to Sabastien for his efforts creating this framework.
Projects I'm involved now requires lots of Many-To-Many relations in E-R
model, so I've tried adding methods (for tranparent access to correlation
entity) as described in the example in UsersGuide 2.6.3. But those methods
doesn't work. So I've copy-pasted example from user's guide, but it did'nt
i.e I add methods getAddresses(), addToAddresses()
-------------
#test.py
from Modeling.EditingContext import EditingContext
from MM1 import Person, Address
ec=EditingContext()
p = Person.Person()
a = Address.Address()
p.addToAddresses(a)
ec.insert(p)
ec.insert(a)
ec.saveChanges()
-----------------
File "./test.py", line 8, in ?
p.addToAddresses(a)
File "/tmp/test2/MM1/Person.py", line 76, in addToAddresses
self.editingContext().insert(_pa)
AttributeError: 'NoneType' object has no attribute 'insert'
-----------------
I've looked into CustomObject.py, and i could'nt find any assigment of
REAL editing, context, only initial definition 'lambda self: None'
Did i misunderstood something, or this example code in User's guide is
just out-dated?
Can someone please give me some guidlines?
I'm using: Python 2.3, Modeling: 0.9-pre-17.1
-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
_______________________________________________
Modeling-users mailing list
https://lists.sourceforge.net/lists/listinfo/modeling-users
---
avast! Antivirus: Saliente mensaje limpio.
Base de datos de Virus (VPS): 0433-1, 09/08/2004
Comprobado en: 10/08/2004 18:09:47
avast! tiene los derechos reservados (c) 2000-2004 ALWIL Software.
http://www.avast.com
Sebastien Bigaret
2004-08-12 20:29:00 UTC
Permalink
Oh well, sorry, I'm sure it's not the first time it's been
reported but left uncorrected, isn't it?
Post by c***@satnet.lt
I've looked into CustomObject.py, and i could'nt find any assigment of
REAL editing, context, only initial definition 'lambda self: None'
Did i misunderstood something, or this example code in User's guide is
just out-dated?
With Erny's correction this should work.

And about CustomObject.editingContext(): it's assigned whenever the object is
inserted or fetched within an EC.

-- Sébastien.
Post by c***@satnet.lt
Hi,
You have to add the instance to both sides of the relation, the
a.setPerson(p)
is missing.
p.addObjectToBothSidesOfRelationshipWithKey(a, ’addresses’)
Erny
Post by c***@satnet.lt
Hello,
First of all thanks to Sabastien for his efforts creating this
framework.
Post by c***@satnet.lt
Projects I'm involved now requires lots of Many-To-Many relations in
E-R
Post by c***@satnet.lt
model, so I've tried adding methods (for tranparent access to
correlation
Post by c***@satnet.lt
entity) as described in the example in UsersGuide 2.6.3. But those
methods
Post by c***@satnet.lt
doesn't work. So I've copy-pasted example from user's guide, but it
did'nt
Post by c***@satnet.lt
i.e I add methods getAddresses(), addToAddresses()
to the class "Person", Then I try to run a code, that uses those
-------------
#test.py
from Modeling.EditingContext import EditingContext
from MM1 import Person, Address
ec=EditingContext()
p = Person.Person()
a = Address.Address()
p.addToAddresses(a)
ec.insert(p)
ec.insert(a)
ec.saveChanges()
-----------------
File "./test.py", line 8, in ?
p.addToAddresses(a)
File "/tmp/test2/MM1/Person.py", line 76, in addToAddresses
self.editingContext().insert(_pa)
AttributeError: 'NoneType' object has no attribute 'insert'
-----------------
I've looked into CustomObject.py, and i could'nt find any assigment
of
Post by c***@satnet.lt
REAL editing, context, only initial definition 'lambda self: None'
Did i misunderstood something, or this example code in User's guide
is
Post by c***@satnet.lt
just out-dated?
Can someone please give me some guidlines?
I'm using: Python 2.3, Modeling: 0.9-pre-17.1
Loading...