On 9/27/07, jawarumnur <[EMAIL PROTECTED]> wrote:
> I think the problem is, that there are two columns ("mother" and
> "father") with a foreign-key that reference the same table.
> sqlalchemie doesn't seem to know, which one to use for which property
> (well, thats quite consequential, as I didn't tell it, which foreign-
> key belongs to which property...).
SQLAlchemy can definitely do this, i.e. have two foreign keys
referencing the same table. I've done something similar.
I'm a little rusty and this is non-tested written-directly-in-email:
persons = Table("persons", meta,
Column("person_id", Integer, primary_key=True),
Column("name", Unicode(128), nullable=False),
Column("is_male", Boolean, nullable=False),
Column("mother_id", Integer, ForeignKey("persons.person_id")),
Column("father_id", Integer, ForeignKey("persons.person_id"))
)
class Person(object):
get_children(self):
if self.is_male:
return self.children_father
else:
return self.children_mother
add_child(self, child):
if self.is_male:
child.father = self
else:
child.mother = self
mapper(Person, persons, properties={
'mother': relation(Person,
primaryjoin=persons.c.person_id==persons.c.mother_id,
backref='children_mother'),
'father': relation(Person,
primaryjoin=persons.c.person_id==persons.c.father_id,
backref='children_father')
})
Arnar
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---