Re: [sqlalchemy] Re: Order by in select doesn't seem to work

2012-01-09 Thread Gaƫtan de Menten
On Tue, Dec 27, 2011 at 16:42, Michael Bayer mike...@zzzcomputing.com wrote: On Dec 27, 2011, at 10:37 AM, VDK wrote: Michael, I simplified my code just for test purposes. I'm now working with only two columns, without order_by clause, commented a few other lines with order by. I'm sure

[sqlalchemy] Eager loading hates single table inheritance

2012-01-09 Thread Yuen Ho Wong
Here's a list of pathological test cases that confuses the hell out of SA while trying to eager load more than 1 collections which are mapped to the same table using single table inheritance. In short, only joinedload*() appears to work out of all the eager loading methods. This pretty much

Re: [sqlalchemy] Eager loading hates single table inheritance

2012-01-09 Thread Michael Bayer
On Jan 9, 2012, at 7:34 AM, Yuen Ho Wong wrote: Here's a list of pathological test cases that confuses the hell out of SA while trying to eager load more than 1 collections which are mapped to the same table using single table inheritance. In short, only joinedload*() appears to work out

[sqlalchemy] Re: 0.7 event migration

2012-01-09 Thread Kent
i guess the patch is interacting with that load_on_pending stuff, which I probably added for you also. It would be nice to really work up a new SQLAlchemy feature: detached/transientobject loading document that really describes what it is we're trying to do here.If you were to write

Re: [sqlalchemy] Eager loading hates single table inheritance

2012-01-09 Thread Michael Bayer
On Jan 9, 2012, at 11:19 AM, Michael Bayer wrote: The first thing I note here is, if I were doing a model like this, I'd either use two different association tables between Product-Origin and Product-Food, or I'd make one relationship(), and handle the filtering in Python (which is

Re: [sqlalchemy] Re: 0.7 event migration

2012-01-09 Thread Michael Bayer
On Jan 9, 2012, at 2:30 PM, Kent wrote: i guess the patch is interacting with that load_on_pending stuff, which I probably added for you also. It would be nice to really work up a new SQLAlchemy feature: detached/transientobject loading document that really describes what it is we're

Re: [sqlalchemy] Re: 0.7 event migration

2012-01-09 Thread Kent Bower
On 1/9/2012 2:33 PM, Michael Bayer wrote: On Jan 9, 2012, at 2:30 PM, Kent wrote: i guess the patch is interacting with that load_on_pending stuff, which I probably added for you also. It would be nice to really work up a new SQLAlchemy feature: detached/transientobject loading document

Re: [sqlalchemy] Re: 0.7 event migration

2012-01-09 Thread Michael Bayer
On Jan 9, 2012, at 2:36 PM, Kent Bower wrote: that means some of the columns being linked to the foreign keys on the target are None. If you want your lazyload to work all the attributes need to be populated. If you're hitting the get committed thing, and the attributes are only

Re: [sqlalchemy] Re: 0.7 event migration

2012-01-09 Thread Kent Bower
On 1/9/2012 5:33 PM, Michael Bayer wrote: On Jan 9, 2012, at 2:36 PM, Kent Bower wrote: that means some of the columns being linked to the foreign keys on the target are None. If you want your lazyload to work all the attributes need to be populated. If you're hitting the get committed

[sqlalchemy] Strange session.commit behavior

2012-01-09 Thread Pavel Ponomarev
Hi, Heard lots of good things about sqlalchemy and decided to give it a try. But almost immediately was confused by strange session.commit() behavior, please look through following snippets. Update is pretty straightforward: obj = MyModel.query.first() obj.attr foo obj.attr = 'bar'

[sqlalchemy] SQL Alchemy Closure Table Relationship Definition

2012-01-09 Thread jonstjohn
I recently started working with SQL Alchemy for a project that involves climbing areas and routes. Areas are hierarchical in that a single area may contain multiple areas, which in turn may contain other areas. A route is directly associated with a single area, but is also associated with that

Re: [sqlalchemy] Strange session.commit behavior

2012-01-09 Thread Michael Bayer
On Jan 7, 2012, at 6:05 PM, Pavel Ponomarev wrote: Hi, Heard lots of good things about sqlalchemy and decided to give it a try. But almost immediately was confused by strange session.commit() behavior, please look through following snippets. Update is pretty straightforward: \And it

RE: [sqlalchemy] Strange session.commit behavior

2012-01-09 Thread Jackson, Cameron
I agree with Mike, I don't think vars(obj).update(kwargs) is the best way to do it. Python trusts the programmer enough to let you bypass the middle layers of abstraction like this, but it's not always a good idea. Besides, it only takes 2 lines to do it with setattr() instead: for key,

Re: [sqlalchemy] SQL Alchemy Closure Table Relationship Definition

2012-01-09 Thread Michael Bayer
On Jan 9, 2012, at 6:51 PM, jonstjohn wrote: To implement this I chose to use a closure table ala Bill Karwin (http://karwin.blogspot.com/2010/03/rendering-trees-with-closure- tables.html). In the closure table implementation, a second table is created to store the ancestor/descendent

Re: [sqlalchemy] SQL Alchemy Closure Table Relationship Definition

2012-01-09 Thread Michael Bayer
typo in the DbArea.ancestors attribute: ancestors = association_proxy(ancestor_rels, ancestor) more demos: print s.query(DbArea).filter_by(name=Kaymoor).one().ancestors print s.query(DbArea).filter_by(name=Kaymoor).one().descendents -- You received this message because you are

Re: [sqlalchemy] Eager loading hates single table inheritance

2012-01-09 Thread Jimmy Yuen Ho Wong
On 10/1/12 12:19 AM, Michael Bayer wrote: A common theme in SQLAlchemy is that, despite all the flak we get for being complicated, SQLAlchemy is actually very simple. It has a handful of constructs which seek to do exactly the same thing in exactly the same way, as consistently as

Re: [sqlalchemy] Eager loading hates single table inheritance

2012-01-09 Thread Jimmy Yuen Ho Wong
Ah Thanks! A bit of a hack but certainly works for now. Thanks for helping out. Really appreciate it! Jimmy Yuen Ho Wong On 10/1/12 3:31 AM, Michael Bayer wrote: On Jan 9, 2012, at 11:19 AM, Michael Bayer wrote: The first thing I note here is, if I were doing a model like this, I'd either

Re: [sqlalchemy] Eager loading hates single table inheritance

2012-01-09 Thread Michael Bayer
On Jan 9, 2012, at 8:56 PM, Jimmy Yuen Ho Wong wrote: In the subqueryload_all()/subqueryload() example, you'll note the second one with two separate subqueryload() calls does in fact correctly do the subqueryload twice. There's no way SQLA would ever figure out automatically that

RE: [sqlalchemy] sql hashed tables

2012-01-09 Thread Jackson, Cameron
Woah, 100 tables of users? That doesn't seem right. How come you don't just have 1 table, 'users', with an id column, and then each user is a row in the table? Likewise for your events. Is there a reason you don't have a single 'events' table, with date as a column, and then each row in the

Re: [sqlalchemy] sql hashed tables

2012-01-09 Thread Michael Bayer
On Jan 9, 2012, at 9:07 PM, Mason wrote: Hi I have 100 tables that go from user_00 to user_99 (based on the last 2 digits of user id). In sql, I can create a view (say 'user') and query 'user' directly. With sqlalchemy, can I do something similar? I would like to query the 'user' class

[sqlalchemy] Re: SQL Alchemy Closure Table Relationship Definition

2012-01-09 Thread jonstjohn
Michael - I greatly appreciate the time and consideration you put into your thorough reply. It has really helped me better understand how SQL Alchemy handles associations. In particular, it is now apparent to me that there is no clear association between area and route, which makes it not

Re: [sqlalchemy] Re: SQL Alchemy Closure Table Relationship Definition

2012-01-09 Thread Michael Bayer
On Jan 9, 2012, at 11:58 PM, jonstjohn wrote: The route and area relationship is similar to the hypothetical problem of a business location. Suppose you have a set of business locations, each in a specific city. The business must be associated with one and only one city. The city is