if you're on declarative then you can say foreign_keys="MyRelatedCls.related_id" or foreign_keys="[MyRelatedCls.related_id]" , all as a string, not a list of strings. You can also send the declarative attribute right in, foreign_keys=MyRelatedClass.related_id. Also I think cls.__mapper__.c has been gone since 0.6, the 'c' attribute is from a Table.
On Feb 11, 2011, at 7:22 PM, Michael Naber wrote: > Thanks for your help. Sorry if I wasn't clear. I was referring to the > foreign_keys keyword argument to relationship, not to ForeignKey. Here is a > link to the relevant doc: > http://www.sqlalchemy.org/docs/orm/relationships.html?highlight=relationship#sqlalchemy.orm.relationship > > Thanks, > Michael > > On Fri, Feb 11, 2011 at 7:45 AM, dalia <[email protected]> wrote: > I'm not sure I understood your question correctly as I'm very new to > sqlalchemy, still I thought u need to know how to declare ForeignKeys > in declarative style. Here is how u can declare it ; for example, > suppose you have 2 tables - > > class A(Base): > __tablename__ = 'a_table' > id = Column(Integer, primary_key=True) > somecol1 = Column(Unicode(20)) > > class B(Base): > __tablename__='b_table' > id = Column(Integer, primary_key=True) > a_id = Column(Integer, ForeignKey('a_table.id')) > somecol2 = Column(Unicode(20)) > > here a_id column of b_table is foreignkey related to the id column of > a_table > > On Feb 11, 9:20 am, Michael Naber <[email protected]> wrote: > > If I'm creating a relationship to a class "MyRelatedClass" using > > declarative syntax, and I need to assign a column from MyRelatedClass > > to the foreign_keys argument, it seems I have to say > > foreign_keys=[MyRelatedClass.__mapper__.c.relate_id]. Is there any way > > to just do something in the declarative style, such as: > > foreign_keys=["MyRelatedClass.relate_id"] with the quotes? > > > > Thanks, > > Michael > > -- > 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. > > > > -- > 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. -- 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.
