On Oct 21, 2008, at 11:28 AM, [EMAIL PROTECTED] wrote:

>
> hi
> in a class hierarcy A,B,C,...
> in order to get "all things that are instances of a subclass of A but
> not A itself", i used somequery().from-statement( subfilter).
> then i found select_from() which allows to do further joins/filter etc
> and now use that.
> but it won't work for polymorphic queries with unions, e.g. concrete
> inheritance (pseudocode):
>
> m = mapper(A, with_polymorphic = ('*',
>    polymunion( A:..., B:..., C:..., ... ), alias=pu_a)
>    )
> allsubs = ses.query(A).select_from(
>    polymunion( B:.., C:.. ), alias=psub_a) #same as above less A
>    )
> this seems to do a vector product:
>
> SELECT psub_a.*
> FROM (SELECT "B".db_id AS db_id, "B".name AS name, "B"."dataB"
> AS "dataB", 'B' AS atype FROM "B") AS psub_a,
> (SELECT "A".db_id AS db_id, "A".name AS name, CAST(NULL AS
> VARCHAR(200)) AS "dataB", 'A' AS atype
> FROM "A" UNION ALL SELECT "B".db_id AS db_id, "B".name AS
> name, "B"."dataB" AS "dataB", 'B' AS atype
> FROM "B") AS pu_a
> ...
>
> is this bug or?

query.select_from(...(B, C)) will issue the SELECT you give it,  
wrapped inside a SELECT based on what the mapper expects to get.  The  
mapper.with_polymorphic(A, B, C) will try to query for A, B and C from  
the selectable given in select_from().   So I'd expect some kind of  
car wreck from that.

In this case you'd be looking for query.with_polymorphic((B,C),  
your_thing(B, C)).

> the other way i can imagine is
> ses.query(A).filter( A.type != 'Aidentity') - but isn't this more
> expensive?

they're all expensive...concrete inheritance is a poor choice for  
polymorphic loading.


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