On Jan 5, 2012, at 9:52 AM, Thijs Engels wrote:

> When going through the (excellent) documentation on relationsship I came
> across this example:
> 
> 
> from sqlalchemy import Integer, ForeignKey, String, Column
> from sqlalchemy.ext.declarative import declarative_base
> from sqlalchemy.orm import relationship
> 
> Base = declarative_base()
> 
> class User(Base):
>  __tablename__ = 'user'
>  id = Column(Integer, primary_key=True)
>  name = Column(String)
> 
>  addresses = relationship("Address",
>    primaryjoin="and_(User.id==Address.user_id, "
>    "Address.email.startswith('tony'))",
>    backref="user")
> 
> class Address(Base):
>  __tablename__ = 'address'
>  id = Column(Integer, primary_key=True)
>  email = Column(String)
>  user_id = Column(Integer, ForeignKey('user.id'))
> 
> 
> What would be required to make this (User) addresses property a method
> with the startwith part a parameter? Can this be done using the
> relationship definitions? Or would it require a method with a explicit
> query in it (which would need the existance of a session)?

there's a path to doing this though not without it's complexities, described at:

http://www.sqlalchemy.org/trac/wiki/UsageRecipes/GlobalFilter


> 
> Kind regards,
> 
> Thijs
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> 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 sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to