What you're really doing here is creating a multiply inherited class  
on the SQL side, which is a use case SQLA was not at all designed to  
handle.    So the fact that RatableRecord inherits from Soup here is  
not ideal since its really a (Ratable, Record).   The specific concept  
we have no test coverage or support for is that a row in ratings and a  
row in records, both subclasses of soup, might share the same primary  
key.   Additionally, SQLA when constructing the join() for joined  
table inheritance assumes the joinable units can be strung together  
like plain tables (all the test coverage involves plain tables as  
targets), so here we have to bypass that functionality altogether.

It can work for the purposes of this example by forcing a particular  
select() statement from the mapping:

orm.mapper(RatableRecord, ratable_record,
             with_polymorphic=([RatableRecord],  
ratable_record.join(soup,  
records.c.id==soup.c.id).select().apply_labels().alias()),
            inherits=Soup, inherit_condition=(records.c.id==soup.c.id))

I can't speak for how far you can go with this (meaning functions  
which construct joins like query.join() as well as eager loading may  
or may not have further issues), and you lock yourself in to a little  
more SELECT nesting than might be strictly necessary at a straight SQL  
level.   The existence of the RatableRecord class and its mapping  
probably makes SQLA's polymorphic loading (i.e., from Soup on upwards)  
a non-option here, but might work to some degree if you specified  
with_polymorphic() on all mappers to force what it selects from in all  
cases.


On Jun 14, 2008, at 6:10 AM, Malthe Borch wrote:

> Michael Bayer wrote:
>> oh.   how are you getting it to join from soup-> (album join
>> vinyl) ?   "soup" has a relation to "album join vinyl" and you're
>> using query.join() ?   it should be creating an aliased subquery for
>> the right side of the join in that case.   I thought 0.4 was able to
>> do this; 0.5 definitely can.
>
> Attached is the example script from my previous thread, adapted to  
> show
> the present issue.
>
> The setup is basically this:
>
>   ratable_record = records.join(
>      ratings, onclause=(ratings.c.id==records.c.id))
>
>   orm.mapper(RatableRecord, ratable_record,
>      inherits=Soup, inherit_condition=(records.c.id==soup.c.id))
>
> \malthe
>
> >
> <example.tar.gz>


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