Hi all,
I have the following error:
sqlalchemy.exceptions.InvalidRequestError: Column 'DownloadTopic.ID'
is
not available, due to conflicting property
'ID':<sqlalchemy.orm.properties.ColumnProperty object at 0xb761732c>
when trying to access the topics field defined by the following model.
It seems to have something to do with all primary key columns having
the
same name but I can't figure out why (schema and table prefixes seem
to be set - at least for the first column).
model = Model()
DownloadTable = Table('Download',
metadata,
PrimaryKeyConstraint('ID'),
ForeignKeyConstraint(('f_DownloadStatusID',),
('myschema.DownloadStatus.ID',)),
schema='myschema',
autoload=True)
class DownloadItem(MappedClassBase):
pass
TopicTable = Table('DownloadTopic',
metadata,
PrimaryKeyConstraint('ID'),
ForeignKeyConstraint(('f_DownloadTopicPortalID', ),
('myschema.DownloadTopicPortal.ID',)),
schema='myschema',
autoload=True)
class TopicItem(MappedClassBase):
pass
mapper(TopicItem, TopicTable)
TopicUseTable = Table('DownloadTopicUse',
metadata,
ForeignKeyConstraint(('f_DownloadID',
'f_DownloadTopicID'), ('myschema.Download.ID',
'myschema.DownloadTopic.ID')),
schema='myschema',
autoload=True)
class TopicUseRecord(MappedClassBase):
pass
# we need something like this:
# select myschema."DownloadTopic".* from
myschema."DownloadTopic"
# inner join myschema."DownloadTopicUse"
# on myschema."DownloadTopic"."ID" =
myschema."DownloadTopicUse"."f_DownloadTopicID"
# inner join myschema."Download"
# on myschema."DownloadTopicUse"."f_DownloadID" =
myschema."Download"."ID"
# where myschema."Download"."HaufeIndex" = 404009
j_primary = join(TopicTable, TopicUseTable,
onclause=TopicTable.c.ID==TopicUseTable.c.f_DownloadTopicID)
j_secondary = join(DownloadTable, TopicUseTable,
onclause=DownloadTable.c.ID==TopicUseTable.c.f_DownloadID)
mapper(DownloadItem, DownloadTable, properties={
'topics' : relation(TopicItem, secondary=TopicUseTable,
primaryjoin=j_primary,
secondaryjoin=j_secondary)
})
model.add('download', table=DownloadTable,
mapper_class=DownloadItem)
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---