On 6/14/06, Michael Bayer <[EMAIL PROTECTED]> wrote:
> no thats possibly a little weird...you should send me what youre
> doing so i can see what thats about. is this only with self-
> referential mappers ?
Well, maybe I'm doing something that's weird. Again, here's a minimal
example - the weirdness comes from having an unenforced ForeignKey,
because there is more than one table that it might refer to (a Car
could belong to a Company, or to a Person)
#### Begin code ####
from sqlalchemy import *
meta = BoundMetaData('sqlite://', echo=False)
company_table = Table('company', meta,
Column('id', Integer, primary_key=True),
Column('name', String),
)
person_table = Table('person', meta,
Column('id', Integer, primary_key=True),
Column('name', String),
)
car_table = Table('car', meta,
Column('id', Integer, primary_key=True),
# owner_id is sort-of, but not really, an FK - it could refer
# to a company or to a person:
Column('owner_id', Integer, nullable=False),
)
meta.create_all()
class Car(object):
pass
class Company(object):
pass
class Person(object):
pass
Car.mapper = mapper(Car, car_table)
Company.mapper = mapper(Company, company_table)
Person.mapper = mapper(Person, person_table)
if True:
# This doesn't work...
Company.mapper.add_property(
'cars',
relation(Car, primaryjoin=(car_table.c.id==company_table.c.id)))
Person.mapper.add_property(
'cars',
relation(Car, primaryjoin=(car_table.c.id==person_table.c.id)))
else:
# but this does.
Company.mapper.add_property(
'cars',
relation(Car, primaryjoin=(car_table.c.id==company_table.c.id),
foreignkey=[car_table.c.id]))
Person.mapper.add_property(
'cars',
relation(Car, primaryjoin=(car_table.c.id==person_table.c.id),
foreignkey=[car_table.c.id]))
#### End code ####
I have been doing something like this for a few days, and it worked
until I synced with svn today.
As you see in the example, I can work around it quite easily, so it's
not slowing down my work.
Chris Perkins
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users