Thank you!

As I'm sure some of the people in the list already know, I also asked
this same question in StackOverflow, and I got a couple of interesting
answers.

Just in case:
http://stackoverflow.com/questions/6118783/sqlalchemy-check-if-one-object-is-in-any-relationship-or-object-relationship1

2011/5/26 Michael Bayer <mike...@zzzcomputing.com>:
> This seems to be an issue of poor documentation on our part.   Here are new 
> documentation elements, linked from the ORM tutorial which was previously the 
> only place contains() was mentioned, fully describing the behavior of 
> contains(), and how any() and outerjoin() are more appropriate if OR 
> conjunctions are used:
>
> http://www.sqlalchemy.org/docs/orm/internals.html#sqlalchemy.orm.properties.RelationshipProperty.Comparator.contains
>
>
> On May 24, 2011, at 7:51 PM, Hector Blanco wrote:
>
>> 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.
>>
>
> --
> 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.
>
>

-- 
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