I get the same result with this in 0.3.10 and 0.4beta5....

Basic idea: I have two tables which hold various data and a third
table which let's different rows in each table be related to another
(many-to-many relationship).

Table/ORM code:
base_table = Table('base_type', metadata,
    Column('id', types.Integer, primary_key=True, autoincrement=True),
    Column('name', types.String(255), nullable=False, default=''),
    Column('pickledData', types.PickleType)
)

people_table = Table('people', sac.metadata,
    Column('id', types.Integer, primary_key=True, autoincrement=True),
    Column('name', types.String(255), nullable=False, default=''),
    Column('email', types.String(255), nullable=False, default=''),
    Column('pickledData', types.PickleType)
)

relations_table = Table('relations', sac.metadata,
    Column('id', types.Integer, primary_key=True, autoincrement=True),
    Column('toObj', types.Integer, default=0),
    Column('fromObj', types.Integer, default=0),
    Column('toType', types.Integer, default=0),
    Column('fromType', types.Integer, default=0)
)

class BaseType(object): # type 0
    pass
class Person(object): # type 1
    pass

mapper(Person, people_table) # <-- not complete yet, just trying to
get basic many-to-many working below
mapper(BaseType, base_table, properties={
    'people': relation(Person, secondary=relations_table,
viewonly=True,
        primaryjoin=and_(people_table.c.id ==
relations_table.c.fromObj, relations_table.c.fromType == 1),
        secondaryjoin=and_(base_table.c.id == relations_table.c.toObj,
relations_table.c.toType == 0),
        foreign_keys=[relations_table.c.fromObj]),
    'base': relation(BaseType, secondary=relations_table,
viewonly=True,
        primaryjoin=and_(base_table.c.id == relations_table.c.fromObj,
relations_table.c.fromType == 0),
        secondaryjoin=and_(base_table.c.id == relations_table.c.toObj,
relations_table.c.toType == 0),
        foreign_keys=[relations_table.c.fromObj])
})


So, I do a query on BaseType, and take the first item and then iterate
through the people property:
base_q = Session.query(BaseType)
item = base_q.get_by(id=0)
if item:
    for person in item.people:
        print person.name

Which raises an exception:
sqlalchemy.exceptions.InvalidRequestError: Column 'people.id' is not
available, due to conflicting property
'id':<sqlalchemy.orm.properties.ColumnProperty object at
0x2aaaaaac3910>


My guess is it's something to do with foreign_keys (from my searching
here, it would appear foreign_keys isn't a way to "pretend" that
foreign keys exist in the schema).

Any help would be greatly appreciated. :)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to