On May 9, 2006, at 7:58 AM, Julien Cigar wrote:

cascade_mappers(Invasive.mapper, InvasiveCategory.mapper) // Invasive contains invasivecategory and InvasiveCategory contains invasives


cascade_mappers is pretty sketchy, while its working for you in this case, i suggest you dont trust it....

It works, but how could I select all "Invasive" order by InvasiveCategory.category ?
I tried things like:

Invasive.mapper.select_by(order_by=[invasivecategory.category])
Invasive.mapper.select(order_by=[InvasiveCategory.c.category]) // This query doesn't fail, but a JOIN is missing ... (why ?)
...

First of all, select_by(), which I am cursing ever having added, does not do "order_by". the "order_by" youre putting in there, as far as it can tell, means "look for a property named 'order_by' on the "Invasive" class", which of course there isnt. all keyword arguments must relate to properties on the Invasive class, therefore theres no order_by, no limit, no offset, etc. all of that stuff is available when you use select().

then when using select(), it requires total explicitness. when you deal with the Invasive mapper, its as though you are sitting at a SQL prompt and querying the "invasive" table, except youre going to get back Invasive objects, not rows. So if you want to select from invasive and order by a relationship to another table, i.e. invasive_category, you have to join:

Invasive.mapper.select (invasives.c.category==invasive_categories.c.id, order_by=invasivecategory.c.category)


Another question, why can't I select only some fields in a select_text() ? For example : Invasive.mapper.select_text('SELECT a.* FROM invasives a, invasive_categories b WHERE a.category=b.id') works but Invasive.mapper.select_text('SELECT a.original_name FROM invasives a, invasive_categories b WHERE a.category=b.id') fails ...


select_text is not a terrific method since its hard to use; it requires that the columns in the result set match exactly what the mapper would normally create on its own. so you cant just select "a.original_name", since the mapper cannot create an "Invasive" object from just a name; you have to select all the columns from the "invasives" table.

if you were doing eager loads, it would be even more difficult (acutally impossible, since it generates aliased column names for related objects). in 0.2, the eager loads will just silently degrade to lazy loads if the proper columns are not present.



-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to