Denis S. Otkidach wrote:
>
> Do you mean I have to create separate model definitions for public and
> private parts of site? It doesn't seem sane to me. I've used such
> filtering across all tables for over 10 years with other DB tools, and
> it saved me a lot of work. Why not using it with SA?

I've never heard of such a feature in a tool like Hibernate, for example.

However, its quite easy to achieve.  Just use this.

class LimitingQuery(Query):
    def get(self, ident):
        return Query.get(self.populate_existing(), ident)

    def __iter__(self):
        return Query.__iter__(self.private())

    @_generative()
    def private(self):
        crit = (self._entities[0].mapper.class_.public == True)
        if self._criterion:
            self._criterion &= crit
        else:
            self._criterion = crit

full test case attached.

0.5.5 will have a new feature "query.disable_assertions(*names)" such that
you can stick to non-underscore names without any errors raised by
limit/one/etc.:

class LimitingQuery(Query):
    def get(self, ident):
        return Query.get(self.populate_existing(), ident)

    def __iter__(self):
        return
Query.__iter__(self.disable_assertions('limit_offset').filter_by(public=True))





--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Attachment: test.py
Description: Binary data

Reply via email to