oops, it looks like the second form  
(session.query(Item).with_polymorphic([FooItem,  
BarItem]).options(eagerload(FooItem.foochild, BarItem.barchild)))  
works fine.

should i go ahead and try to write test cases?

  - Jae

On Aug 29, 2009, at 2:23 PM, Jae Kwon wrote:

> I looked at this further, i think I got it working half way.
>
> Index: lib/sqlalchemy/orm/util.py
> ===================================================================
> --- lib/sqlalchemy/orm/util.py        (revision 6072)
> +++ lib/sqlalchemy/orm/util.py        (working copy)
> @@ -387,6 +387,7 @@
>         if left_mapper or right_mapper:
>             self._orm_mappers = (left_mapper, right_mapper)
>
> +            parent_mapper =  
> onclause.parententity._AliasedClass__mapper
>             if isinstance(onclause, basestring):
>                 prop = left_mapper.get_property(onclause)
>             elif isinstance(onclause, attributes.QueryableAttribute):
> @@ -411,6 +412,9 @@
>                     onclause = sj
>                 else:
>                     onclause = pj
> +
> +                if parent_mapper._single_table_criterion:
> +                    onclause = sql.and_(onclause,  
> parent_mapper._single_table_criterion)
>                 self._target_adapter = target_adapter
>
>         expression.Join.__init__(self, left, right, onclause, isouter)
>
>
> It works for queries of the form :
>    items =  
> session 
> .query 
> (Item).with_polymorphic([FooItem]).options(eagerload(FooItem.child))
> but not :
>    items = session.query(Item).with_polymorphic([FooItem,  
> BarItem]).options(eagerload(FooItem.foochild, BarItem.barchild))
>
> I'll keep trying around for a solution that solves the above, and  
> then hopefully someone more knowledgeable can pick it up or guide me.
>
> - Jae
>
>
>
>
>
>
> On Aug 28, 2009, at 4:43 PM, Jae Kwon wrote:
>
>>
>> I've seen similar discussions here, but it's been a while so perhaps
>> things have changed.
>>
>> class Foo(Base):
>> __tablename__ = 'foo'
>> type = Column(Integer)
>> __mapper_args__ = {'polymorphic_on': type}
>> ...
>>
>> class BarFoo(Foo):
>> __mapper_args__ = {'polymorphic_identity': 1}
>> bar_id = Column(Integer)
>> # relations
>> bar = relation('Bar')
>>
>> class BazFoo(Foo):
>> __mapper_args__ = {'polymorphic_identity': 2}
>> baz_id = Column(Integer)
>> # relations
>> baz = relation('Baz')
>>
>> ## assume existence of Bar and Baz objects
>>
>> Is there a way to say, query all Foo objects while eager-loading the
>> bar/baz relations?
>>
>> - Jae
>>
>>
>> >>
>


--~--~---------~--~----~------------~-------~--~----~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to