On Nov 6, 2006, at 3:31 PM, Randall Smith wrote:

>
> dmiller wrote:
>> Is there a reason why this doesn't work:

...

>> order = session.query(Order).get(1) # assume order exists
>> itemsNotInOrder = session.query(Item).select(Item.c.order != order) #
>> ERROR!
>
> This should work.
> itemsNotInOrder = session.query(Item).select(Item.c.order_id !=  
> order.id)

Thanks for the response Randall. I know that works...read on below.

>
>>
>>
>> The Item.c object does not have an 'order' attribute. Is there a
>> reason why it can't have one?
>
> I would guess that attributes of Item.c are Column instances, which
> order is not.  Your approach seems intuitive (I did the same thing
> once), but the above example I think is easy enough.
>
> I could be wrong or missing something.  Just trying to be helpful.

What I'm getting at is that SA has all the necessary details to  
create the WHERE clause automatically (it already does something very  
similar when constructing joins). My case is a simple case with a  
single-column foreign key (it's even a pretty stupid case at that :).  
However, it demonstrates a powerful query construction concept that  
seems to be lacking from SA. Ideally it should also work with a multi- 
column foreign key, which is much more tedious to do manually (as you  
suggested) because it requires a separate condition for each column  
in the key. It seams like this would be fairly simple to add, maybe  
I'll give it a try if I can find the time.

~ Daniel

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

Reply via email to