On Oct 23, 2013, at 4:33 PM, Jonathan Vanasco <[email protected]> wrote:
> this has just confused me for a while , and constantly trips me up...
>
> class FirstTable()
> __tablename__ = 'first_table'
> id = Column(Integer, primary_key=True)
>
> class SecondTable()
> __tablename__ = 'second_table'
> id = Column(sa.Integer, primary_key=True)
> first_table_id = Column(sa.Integer, ForeignKey("first_table.id") )
> first_table = relationship("FirstTable", primaryjoin="""FirstTable.id
> == SecondTable.first_table_id""")
>
> was there a specific reason why the string in `ForeignKey` is for the
> table+column, and not an object, like in `relationship` ? ( i know that
> `ForeignKey` can take an object too , i'm just wondering about the string )
ForeignKey is a Core feature so doesn’t know about class names, only table
names in the “metadata” object.
The switching between class/table names phenomenon is due to Declarative - in
the old days there was no string-level ORM config (there wasn’t even
ClassName.column - things were much simpler, though much more tedious). Now
it’s gotten kind of confusing if one doesn’t know exactly which constructs come
from where. So it’s not like it didn’t start consistently, it’s just adding
of convenience features begins to shroud the fundamentals (which is why adding
convince is controversial).
we can of course keep adding hooks to things so that both kinds of objects are
accepted everywhere as strings or objects. Declarative would probably need to
scan through for ForeignKey objects and modify them.
>
> --
> 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/groups/opt_out.
--
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/groups/opt_out.