Ok, the real world structure was a little bit more comnplicated, but
it worked out this way.
There is only one problem left, regarding the the name of the FK
column which is responsible for resolving the inheritance.
For constructing my join condition, i need to know the name of that
column. Sometimes it is id, sometimes it is for example foo_id.

I searched with

print dir(class_mapper(MyClass).mapped_table)
print dir(class_mapper(MyClass).local_table)

and so on...
I did not find a way to resolve the name of the column which is
responsible for inheritance.

On 27 Okt., 22:04, Michael Bayer <[EMAIL PROTECTED]> wrote:
> On Oct 27, 2008, at 4:57 PM, Matthias wrote:
>
>
>
> > At the moment i use a workaround which does exactly that what you
> > mentioned. It is a 'wanted class' query string discriminator.
> > With the example this would work properly. The only thing i do not
> > know is how to get the 'polymorphic_identity' which is defined in the
> > mapper. How can i retrieve this String when only the class is given?
>
> you could say "class_mapper(MyClass).polymorphic_identity".
>
>
>
>
>
> > But there is still my bigger problem, of course we have to modify the
> > scenario:
>
> > class Parent(object):
> > class Child(Parent):
> > class SubChild1(Child):
> > class SubChild2(Child):
>
> > Now i want to get all Child objects, this means all Child, Subchild1
> > and Subchild2 objects.
>
> > result = session.query(Child).from_statement(stmt).all()
>
> > The parent class of Subchild1 and Subchild2 - Child does not know
> > anything about any subclasses.
>
> > So if i only have the Child class i can not imagine a smart way to
> > solve this, because in plain SQL i need all possible type values.
> > The nice thing about SQLAlchemy was the automatic inheritance
> > resolver.
>
> the Query() object, if you were not using from_statement(), would  
> generate SQL that joins from the parent to child table and returns all  
> rows.  This returns for you all Child, SubChild1, and SubChild2  
> objects.  parent rows which are not child rows wont be returned since  
> they do not join to child.  The remaining columns from subchild1 and  
> subchild2 are loaded in separate SELECT statements.
>
> If OTOH you were using single table inheritance, the Query would in  
> fact produce a clause like parent.type.in_('child', 'subchild1',  
> 'subchild2').
>
> But for joined table inheritance, the join you're looking for here is:
>
> select * from parent JOIN child on parent.id=child.id
>
> that way you also don't need to know the discriminator.
--~--~---------~--~----~------------~-------~--~----~
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