First of all, thanks for your answer :) # defInst.PlatformRel = [platf] # change this to platf.definitions = defInst
I don't have any "definitions" attribute within the PlatformClass, i suppose you mean the foreign key, isnt'it? That is platf.platformId_fk = defInst However, this results in another error: sqlalchemy.exc.InterfaceError: (InterfaceError) Error binding parameter 1 - probably unsupported type. u'INSERT INTO platform (platform, "definitionId_fk") VALUES (?, ?)' ['Microsoft Windows 2000', <ORM_Classes.DefinitionClass object at 0x8f5278c>] I've played a little with it, then i've moved the relation() from DefinitionClass to PlatformClass: class PlatformClass(Base): __tablename__ = 'platform' platformId = Column(Integer, primary_key=True) platform = Column(String) platformId_fk = Column('definitionId_fk', Integer, ForeignKey('definitions.defId')) PlatformRel = relation(DefinitionClass, backref="platform") and then: platf.PlatformRel = defInst Now i got the expected data! It WORKS :P Thanks Werner! But, i need to understand.. why now it's working? >From the doc: "We are also free... to define the relationship()<http://www.sqlalchemy.org/docs/reference/orm/mapping.html#sqlalchemy.orm.relationship>only on one class and not the other. It is also possible to define two separate relationship()<http://www.sqlalchemy.org/docs/reference/orm/mapping.html#sqlalchemy.orm.relationship>constructs for either direction, which is generally safe for many-to-one and one-to-many relationships, but not for many-to-many relationships." Maybe i don't have well understood the role of the relation()/relationship() function but, shouldn't be the same thing to define the relation() within the DefinitionClass? I've only changed the location of the relation() and now it works. Can you kindly better explain me the role of the relationship() function? Mmm... please correct me if i'm wrong: - "The relationship between the User and Address classes is defined separately using the relationship()<http://www.sqlalchemy.org/docs/reference/orm/mapping.html#sqlalchemy.orm.relationship>function" OK, and is the only way to define a relation between two tables. - If i put relationship() in both classes i got a *bidirectional*relationship - "Because of the *placement* of the foreign key, from Address to User it is *many to one*..." !!! Oh, is this the point, right? If, in the same class, i define a foreign key AND a relationship() i create a many to one relation with the linked table - "..., and from User to Address it is *one to many*" - This is valid only in the bidirectional case or it's "automatic" when i declare somewhere foreign key + relationship() ? - Initially i've defined the foreign key in the PlatformClass and the relation() in the DefinitionClass. Which type of relation i've created in that way? Thanks again! On Fri, Mar 26, 2010 at 4:50 PM, werner <wbru...@free.fr> wrote: > Hi Masetto, > > On 26/03/2010 16:01, masetto wrote: > .... > > Maybe it's a stupid problem but i can't figure it out at the moment :/ >> >> Code: >> ... >> for definitions in ovalXML._childrenMap['definitions']: >> for definition in definitions.getchildren(): >> defInst = ORM_Classes.DefinitionClass(definition) >> > session.add(defInst) # I think this line should be here, > you have it further down > >> ... >> if subElem1.tag == mainNS + "platform": >> platf = ORM_Classes.PlatformClass() >> platf.setPlatform(str(subElem1)) >> >> # defInst.PlatformRel = [platf] # change this to >> > platf.definitions = defInst > > Werner > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com<sqlalchemy%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.