does anyone know if its possible to implement some form of eagerloading or 
class attribute where only the presence (or first record, or count) of 
relations are emitted?

I have a few queries where i'm loading 100+ rows, but I only need to know 
whether or not any entries for the relationship exists.  

the best thing I've been able to come up with, is memoizing the count or a 
bool onto an object as a property:

    @property
    def count_RELATION(self):
        if self._count_RELATION is None:
            _sess = sa.inspect(self).session
            self._count_RELATION = 
_sess.query(self.__class__).with_parent(self, "RELATION").count()
        return self._count_RELATION
    _count_RELATION = None

    @property
    def has_RELATION(self):
        if self.has_RELATION is None:
            _sess = sa.inspect(self).session
            self.has_RELATION = True if 
_sess.query(self.__class__).with_parent(self, "RELATION").first() else False
        return self.has_RELATION
    has_RELATION = None    

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to