I'm working with a MySQL setup that has, say, a Studio database (or
schema), and multiple Production schemas (Production_1, Production_2, etc).
The Studio database has a "seasons" table, and the Production databases
have "episodes" tables. Currently, the episodes table doesn't have a
foreign key linkage back to Production.productions (there isn't even a
column containing the "id" from Production.productions), the original PHP
usage didn't work this way. For SQLAlchemy, I'd like to create a
relationship so that if I have an engine for, say, Production_1, a
retrieved "episodes" object does the many->one back to its "productions"
parent. Things are something like this:
class Production(Base):
__table_args__ = {'schema':'Studio'}
id = Column('id', Integer, primary_key=True, nullable=False)
class Episode(Base):
...
# some sort of relationship() back to Production, even though there is no
column to use as a foreign key
"Creating Custom Foreign Conditions" documents the remote() and foreign()
functions, and I was wondering if these could be used somehow. I've played
around with something like
production = relationship("Production",
primaryjoin=remote(Production.id)==foreign(???))
but I can't seem to find anything that works. I can provide some sort of
instance method or property with the necessary id value for foreign(), but
I'm not sure if this is acceptable, or even if the remote reference is
correct (I've tried the string "Studio.productions.id" as well as the
Production.id variable.
I could probably add a "production_id" column to the episodes table - it
would get filled with the same value for all records in a particular
Production_?.episodes table. That would let me do a normal foreign_key
relationship and shouldn't break the legacy PHP access. But I was curious
if there is a way to torture SQLAlchemy into creating this sort of
non-column relationship?
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.