hi all,

i have a class that have a self reference through *_parent*. this class is mapped against an selectable, not a class (this information is useful, lol)

ok, so, using @hybrid_property, i can easily get the amount of children of this class:


*@hybrid_property**
**def child_count(self):**
**    kls = self.__class__**
**    session = object_session(self)**
**    sel = select(**
**         [**
**             func.count(kls.id_)**
**         ],**
**         and_(**
**             self.id_ == kls._parent,**
**             or_(**
**                 self.language_id == kls.language_id,**
**                 kls.language_id.is_(sql.null())**
**             )**
**         )**
**    )**
**    return session.execute(sel).scalar()*


but, how can I transform it into an expression, so I can use it on a query, like *session.query(cls).filter(cls.child_count == 3).all()* ? i already did a lot of *@some_property.expression*, but I'm having a bit of a trouble on this one :)

any help would be appreciated ...


best regards,
richard.

--
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to