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.
okay, would the join() also need .select(correlate=False) on it, or SA will not mistake it?

Next variant, if tables are concrete, it does same mistake - so i have to specify employee_table.select( correlate=False) instead of plain employee_table in the polymorphic_union. Anything else?

And, as i understand this applies only to things that go in a polymorphic_union; otherwise the correlate=False is not needed.


the polymorphic union thing is one of the most ambitious queries
SQLAlchemy's ORM produces.  which is why I still have not made it
Speaking of polyunion, i have made another version of your helper function. Your variant works ok if all tables under the poly-base are inherited in same way, i.e. either all are concrete_table, or all are table_inheritance. My version (~5-6 lines changed) does not require this (see attached file), and works ok for any type of mixed inheritance.

btw, this correlate=False can be added automaticaly in the polyunion(). i've added it there and it seems to work... What do u think?

ciao
svil

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

Attachment: polymunion.py
Description: application/python

Reply via email to