On May 16, 2013, at 03:09 , Ji Zhang <zhangj...@gmail.com> wrote:

> Hi,
> 
> Say I have a Request model and User model:
> 
> class Request(Base):
>   id = Column(Integer, primary_key=True)
>   user_id = Column(Integer)
>   admin_id = Column(Integer)
> 
> class User(Base):
>   id = Column(Integer, primary_key=True)
>   username = Column(String)
> 
> The Request is created by a user (User) and get verified by an admin (also a 
> User). How to get both request.user and request.admin?

You will need to specify the foreign keys used for the relation ship:

class Request(Base):
    user_id = Column(Integer, ForeignKey('user.id'))
    user = relationship(User, foreign_keys=[user_id])
    admin_id = Column(Integer, ForeignKey('user.id'))
    admin = relationship(User, foreign_keys=[admin_id])

You can find more details in the SQLAlchemy documentation: 
http://docs.sqlalchemy.org/en/rel_0_8/orm/relationships.html#handling-multiple-join-paths

Wichert.

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to