On 4/10/07, svilen <[EMAIL PROTECTED]> wrote: > can u give some exampe, how this is supposed to be used (finaly)? > as relation and/or directly as Query()
Attached is a simple example. The setup is done using Elixir but the actual Query.from_attr usage would be the same with plain SA. If you really need a plain SA example, just ask. > > On Tuesday 10 April 2007 17:22:45 Gaetan de Menten wrote: > > On 3/31/07, Michael Bayer <[EMAIL PROTECTED]> wrote: > > > On Mar 31, 2007, at 1:17 PM, Gaetan de Menten wrote: > > > > That's approximately what I did in my patch with the new > > > > "params" keyword argument, except I only implemented the "set" > > > > operation, not the add operation on the params. Anyway, what > > > > can/should I do to get this included? Do you have any > > > > advice/pointers on how to do the same for eager attributes? (or > > > > will you implement it yourself?) > > > > > > im totally into a series of engine/execution patches/refactorings > > > right now, so for properties that have "lazy=False", there is > > > still a LazyLoader strategy there...you should just call > > > property._get_strategy(LazyLoader) in all cases to get at it. > > > > In case anybody is interested, here is my patch slightly modified > > with what you suggest above. Now it works wonders for both lazy and > > eager relationships. There is something ugly about it though: > > imports. I have to import the LazyLoader class from the > > orm.strategies module, but that module imports query, so what I did > > is import the LazyLoader class inside the from_attr method to avoid > > a "circular import" problem. > > > > By the way, should I create a ticket for this? > > -- Gaƫtan de Menten http://openhex.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---
from sqlalchemy import * from elixir import * class A(Entity): has_field('name', String(30)) has_many('b', of_kind='B', lazy=False) class B(Entity): has_field('name', String(30)) has_field('extra', Integer) belongs_to('a', of_kind='A') metadata.connect('sqlite:///') create_all() a1 = A(name='a1') b1 = B(name='b1', a=a1, extra=10) b2 = B(name='b2', a=a1) b3 = B(name='b3', a=a1, extra=5) b4 = B(name='b4', a=a1, extra=4) b5 = B(name='b5', a=a1, extra=7) objectstore.flush() objectstore.clear() #metadata.engine.echo = True a = A.get_by(name='a1') print "normal" q = Query.from_attr(a, 'b') for b in q: print b.name, b.extra print "filtered extra < 8" for b in q.filter(B.c.extra < 8): print b.name, b.extra print "ordered by extra" for b in q.order_by(B.c.extra): print b.name, b.extra