On May 24, 2007, at 5:34 PM, Brendan Arnold wrote:

>
> Hi there,
>
> I have a principal object (Person) with another group of objects
> (Address) grafted on through the properties={ 'addresses' :
> relation(Address, secondary = ...)} functions in the mappers
>
> I want to select all Person objects that have particular joined
> objects (i.e. select by joined object's 'id')
>
> If my principal object did not have the 'id' method I could just use
>
> results = model.People.select_by(id=3)
>
> However it does have the id property. I try
>
> query_address = model.Address()
> query_address.id = '13 Cemetary Road'
> results = model.People.select_by(addresses = query_address)
>

thats an interesting hack there.  query_address is not persisted, i  
dont exactly understand why youd want to go through the effort to  
create an object that way, instead of

        People.query().join('addresses').filter_by(id=='13 Cemetary  
Road').list()

I just checked to see if you could also say:

        People.query().join('addresses').select_by(id=='13 Cemetary Road')

but you cant, since select_by() is not looking that we already joined  
to 'addresses' whereas filter_by() is.  I think perhaps that should  
be changed.

> However this only works if _all_ object properties match
>
> Finally I try
>
> results = model.People.select_by(model.address_table.c.id==3)
>
> But this (weirdly) returns _all_ People entries in my table regardless
> of what Address they have.

youre lacking the join between people/addresses and getting a  
cartesian product.  select_by's "autojoin" behavior only applies to  
the string keyword arguments sent to its **kwargs, not the  
ClauseElements sent to its *args.




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

Reply via email to