in both test cases, the stack trace reveals that the error occurs
during the lazy load operation of the child items:

 File "test_case2b.py", line 57, in ?
   print a.manager
  ...
 File
"/Users/classic/dev/sqlalchemy/lib/sqlalchemy/orm/strategies.py", line
220, in lazyload

the query being issued is:

SELECT p_union.atype AS p_union_atype, p_union.manager_id AS
p_union_manager_id, p_union.name AS p_union_name, p_union.id AS
p_union_id \nFROM (SELECT anon_e513.manager_id AS manager_id,
anon_e513.atype AS atype, anon_e513.id AS id, anon_e513.name AS name
\nFROM (SELECT "Employee".id AS id, "Employee".name AS name,
"Employee".atype AS atype, "Employee".manager_id AS manager_id \nWHERE
"Employee".atype = ?) AS anon_e513) AS p_union, "Employee" \nWHERE
"Employee".manager_id = ? ORDER BY p_union.oid

if you read closely, you can see that the embedded query for selecting
the employee is wrong; it has no FROM clause:

SELECT "Employee".id AS id, "Employee".name AS name, "Employee".atype
AS atype, "Employee".manager_id AS manager_id \nWHERE "Employee".atype
= ?

SQLite is a little dumb in that it doesnt give a reasonable error
message for this condition (other DB's do).

when you see a SELECT that has no FROM, it usually means SA is trying
to "correlate" the select as a subquery to the enclosing query.  this
will occur anytime a select involving the "employee" table occurs
within another select involving the "employee" table.  in this case its
clearly wrong.

so the "fix" is just to insure that the subquery doesnt get
"correlated":

ajoin = {
   'Employee': employee_table.select( employee_table.c.atype
=='Employee', correlate=False),
   'Manager': join( employee_table, manager_table,manager_table.c.id
==employee_table.c.id),
}

and all is well again.

the polymorphic union thing is one of the most ambitious queries
SQLAlchemy's ORM produces.  which is why I still have not made it
"automatic", i.e. you have to explicitly create it yourself (even
though theres a helper function).  its also why its still plastered
with all those "alpha feature" warnings.

I think if theres a change to be made to SA its that I have to try a
little harder to insure that the "auto-correlation" doesnt result in a
SELECT that has no FROM, meaning this little confusion wouldnt occur.


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