On Thu, Sep 10, 2009 at 23:27 +0200, Wolodja Wentland wrote:
> Hi all,
> 
> I observed that if I define a relation (foo_query) as lazy='dynamic' and
> access all referenced entities with foo_query.all() that the query will
> be executed every time i access it. That is not a big surprise ;-)
> 
> In a library I am writing i want to provide methods that allow
> pre-filtering of referenced entities and also on that provides access to
> all entities. I am wondering if it is better/faster/.. to define *two*
> relations for filtering and accessing all entities respectively.
> 
> I can't really decide between the following two approaches and would be
> happy if someone could provide some tips:
> 
> Approach 1
> ----------
> 
> Class Bar(object):
> 
>     def all_foo(self):
>         foo_query.all()
> 
>     def foo_startwith(self, search_string):
>         foo.query.filter(tbl.c.col.like('%s%%'% ...))
> 
> mapper(Bar,
>        ...
>        properties={
>          'foo_query': relation(Foo, lazy='dynamic')
>          })
> 
> Approach 2
> ----------
> 
> Class Bar(object):
> 
>     def foo_startwith(self, search_string):
>         foo.query.filter(tbl.c.col.like('%s%%'% ...))
> 
> mapper(Bar,
>        ...
>        properties={
>          'all_foo': relation(Foo)
>          })
>        properties={
>          'foo_query': relation(Foo, lazy='dynamic')
>          })
> 
> Which one is faster? Does it make a difference, given the
> optimisation/cache in the database? Will it just mean more bloat in the
> mapper definition?

Nobody can help with the decision?

Wolodja Wentland

Attachment: signature.asc
Description: Digital signature

Reply via email to