not like ive been digging into your specific issues recently, but i  
added a flag that made the new abc tests a lot easier, for this PG  
issue in particular.  the polymorphic unions look like this now:

             abcjoin = polymorphic_union(
                 {"a":ta.select(tb.c.id==None, from_obj=[ta.outerjoin 
(tb, onclause=atob)]),
                 "b":ta.join(tb, onclause=atob).outerjoin(tc,  
onclause=btoc).select(tc.c.id==None, fold_equivalents=True),
                 "c":tc.join(tb, onclause=btoc).join(ta, onclause=atob)
                 },"type", "abcjoin"
             )

             bcjoin = polymorphic_union(
             {
             "b":ta.join(tb, onclause=atob).outerjoin(tc,  
onclause=btoc).select(tc.c.id==None, fold_equivalents=True),
             "c":tc.join(tb, onclause=btoc).join(ta, onclause=atob)
             },"type", "bcjoin"
             )

the new flag being "fold_equivalents".   that will make a join that  
normally looks like this:

        select a.id, a.data, b.id, b.otherdata from a join b on a.id=b.id

into this:

        select a.id, a.data, b.otherdata from a join b on a.id=b.id

at jonathan ellis' suggestion, its not based on the names of the  
columns alone, its also checking that "a.id=b.id" so it "knows" they  
are equivalent.  this instantly solves all the stupid PG issues that  
keep coming up with these unions.

This change then required me to adjust the "polymorphic relationship"  
stuff to look a little harder for "equivalent" columns when  
constructing the join conditions between polymorphic mappers.  an  
example, if inheritance chain A->B->C all joins on an "id" column,  
i.e. a.id, b.id, c.id, but the polymorphic union only contains  
"a.id", it will know that "b.id" is equivalent to both "a.id" and  
"c.id", and that "c.id" is equivalent to both "b.id" and "a.id".   
previously it would only know one of the two "equivalents" which was  
frequently the wrong column to look for.  that change should help  
some of your issues.


On Mar 2, 2007, at 9:40 AM, svilen wrote:

>
>>> hi.
>>> i have the case of polymorphic mapper referencing itself (or
>>> other of it's sub-class objects), and i want to query/filter on a
>>> value of the referenced object.
>>> e.g. all people who have friends of age > 25.
>>
>> these are highly highly complex queries and im not sure if the
>> Query SQL compiler is really appropriate for this; you probably
>> want to go with rolling your own select statements for this.  that
>> or perform separate queries for each subclass and then combine the
>> results in Python (this might be something SA does automatically in
>> the future, as its the only way Hibernate does polymorphic loads).
>
> hmmm.
> i have a product of 2 polymorphisms combined here.
> If impossible to do as 1 query, i could split one of them into
> separate simpler selects, and have for each a polymorphic union
> against a table (or table.join.select), but this won't work either
> (case 3).
>
> The query itself, if fixed manualy, works:
> SELECT ...
> FROM (...) as pu_human, human as humanalias
> WHERE pu_human.friend_id = humanalias.db_id AND humanalias.age > ?
>
> while the SA does:
> SELECT ...
> FROM (...) as pu_human
> WHERE pu_human.friend_id = pu_human.db_id AND pu_human.age > ?
>
> is it some .corresponding_column() taking ownership of too many
> things?
>
> btw; i think i tried the other way, e.g. table against
> polymorhic_union, that produced right FROMs but still wrong WHERE..
>
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to