Hello everybody...

Let's say I have a class like this:

class Foo(declarativeBase):
      bars1 = relationship(Bar.Bar, secondary=foos_to_bars1,
collection_class=set())
      bars2 = relationship(Bar.Bar, secondary=foos_to_bars2,
collection_class=list())

At a certain point, I want to get instances of "Foo"s that have a
"bar" (instance of Bar.Bar) in any of the relationships.

If I try to do:

def inAnyBar(bar)
    query(Foo).filter(or_(Foo.bars1.contains(bar),
Foo.bars2.contains(bar)).all()

I get an empty result.

It looks (to me) like I'm doing something like:

query(Foo).join(Foo.bars1).filter(Foo.bars1.contains(bar)).join(Foo.bars2).filter(Foo.bars1.contains(bar))

Since Foo.bars1 doesn't contain bar, the second filter gives empty results.

I've been able to find a workaround with subqueries (each join+filter
in a subquery, then or_ all the subqueries) but I'd like to know if
there's a better way to do it...

I'm still using SqlAlchemy 0.6.6, though.

Thank you!

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to