lazy = 'dynamic' and coercing AppenderQuery to a new object class

772 views
Skip to first unread message

Zippy P

unread,
Jul 27, 2010, 1:23:28 PM7/27/10
to sqlal...@googlegroups.com
Hi all,

I have the following:

class Device(Base):
...
  source_id = Column(BigInteger, primary_key=True)
...

class EventQuery(Query):
  def custommethod():
    ...

class Event(Base):
  __tablename__ = 'events'
  query = Session.query.property(query_cls = EventQuery)
...
  device_source_id = Column(BigInteger, ForeignKey("Device.source_id"))
  device = relationship(Device, backref=backref('events', lazy='dynamic'))
...

Now, Device.events returns a query of type AppenderQuery, which is fine for some built-in methods like count() and all(). What I really need is for this to be a query of type EventQuery, so I can call Device.events.custommethod(). 

1) Is it possible to coerce AppenderQuery into a different Query class?
2) If not, is it appropriate to create a custom property on Device that will return an EventQuery containing the equivalent query, or is there a more proper way to do it?

Thanks,

S.

Michael Bayer

unread,
Jul 27, 2010, 2:03:20 PM7/27/10
to sqlal...@googlegroups.com

relationship() and backref() accept query_class for this purpose.


>
> Thanks,
>
> S.
>
>
> --
> You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
> To post to this group, send email to sqlal...@googlegroups.com.
> To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.

Reply all
Reply to author
Forward
0 new messages