On May 10, 2014, at 11:58 PM, Joseph Casale <[email protected]> wrote:
> Hey Michael,
>
> Lets say I have a table TableA:
>
> class TableA(Base):
> __tablename__ = 'table_a'
>
> id = Column(Integer, primary_key=True)
> name = Column(String(collation='nocase'), unique=True, nullable=False)
>
> Then TableB:
>
> class TableB(Base):
> __tablename__ = 'table_b'
>
> id = Column(Integer, primary_key=True)
> name_id = Column(Integer, ForeignKey('table_a.id', ondelete='CASCADE'),
> nullable=False)
> name = relationship(TableA)
>
> Is there any way I can build TableB so that a consumer can pass just the
> string value of the
> intended reference (table_a.name) to table_b.name and have the orm infer the
> reference?
I don't understand. Do you mean at the configuration level? e.g.:
class TableB(Base):
# ...
name = relationship(TableA) # "name_id" is auto created?
if so, check out the recipe here:
https://bitbucket.org/zzzeek/pycon2014_atmcraft/src/a6d96575bc497ce0c952bb81db9c05d054c98bb5/atmcraft/model/meta/orm.py?at=master#cl-5
/
https://bitbucket.org/zzzeek/pycon2014_atmcraft/src/a6d96575bc497ce0c952bb81db9c05d054c98bb5/atmcraft/model/meta/schema.py?at=master#cl-12
, background is at: http://www.sqlalchemy.org/library.html#buildingtheapp.
this is a modernized version of what I did a few years ago here:
http://techspot.zzzeek.org/2011/05/17/magic-a-new-orm/.
otherwise if you mean at the query level or building objects level, I'm not
sure what you're asking.
--
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.
For more options, visit https://groups.google.com/d/optout.