[sqlalchemy] Dynamic relationship in queries

2013-07-28 Thread askel
Hello everybody, I've been tearing my hairs out trying to figure out how to achieve the following. Base = declarative_base() class Group(Base): g_id = Column(Integer, primary_key=True) events = relationship('Event', backref='group', lazy='dynamic') class

Re: [sqlalchemy] Dynamic relationship in queries

2013-07-28 Thread Michael Bayer
On Jul 28, 2013, at 9:29 AM, askel dummy...@mail.ru wrote: What I have ended up with is the following: class Group(Base): events = relationship('Event', lazy=True) session.query(Group).join(Group.events).options(contains_eager(Group.events).filter(Event.e_date=='2013-01-01') The

Re: [sqlalchemy] Dynamic relationship in queries

2013-07-28 Thread askel
Thanks for the reply. I'll stick with *contains_eager* solution as per your advice. That *bindparam* trick would work in this particular case too but I like flexibility of using former solution. - alex On Sunday, July 28, 2013 11:50:29 AM UTC-4, Michael Bayer wrote: On Jul 28, 2013, at 9:29

[sqlalchemy] Dynamic relationship

2011-06-02 Thread Ben Chess
Hi, I want to establish a relationship with an object whose key is defined inside a JSON BLOB column in the child. Naively, I know I can do this via a regular python @property that uses object_session() to then do a query() using the id from inside the blob. Is there a better way that lets

Re: [sqlalchemy] Dynamic relationship

2011-06-02 Thread Michael Bayer
Using a BLOB as a key is a really bad idea and wont work on all backends, but other than the database-level limitations inherent, SQLAlchemy will let you set up whatever column you'd like to use as the key just fine within a relationship(). Guessing what the problem might be. Foreign key ?

Re: [sqlalchemy] Dynamic relationship

2011-06-02 Thread Ben Chess
I'm not intending for the contents of the BLOB to be readable to MySQL. It would only be cracked open and read from within Python. Meaning Python only knows what the key actually is. So yeah, I understand the caveats of this approach. I merely want to provide a mechanism to, as a second

Re: [sqlalchemy] Dynamic relationship

2011-06-02 Thread Ben Chess
On Thu, Jun 2, 2011 at 5:18 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Jun 2, 2011, at 8:11 PM, Ben Chess wrote: I'm not intending for the contents of the BLOB to be readable to MySQL.  It would only be cracked open and read from within Python. Meaning Python only knows what the

Re: [sqlalchemy] Dynamic relationship

2011-06-02 Thread Michael Bayer
On Jun 2, 2011, at 8:25 PM, Ben Chess wrote: On Thu, Jun 2, 2011 at 5:18 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Jun 2, 2011, at 8:11 PM, Ben Chess wrote: I'm not intending for the contents of the BLOB to be readable to MySQL. It would only be cracked open and read from

Re: [sqlalchemy] Dynamic relationship

2011-06-02 Thread Ben Chess
Sounds far more complicated than something I'd want to take on. Thanks for your thoughts and the detailed response. Ben On Thu, Jun 2, 2011 at 6:28 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Jun 2, 2011, at 8:25 PM, Ben Chess wrote: On Thu, Jun 2, 2011 at 5:18 PM, Michael Bayer