Hello.

I have tried the variant for SA 0.7. The query I tried is this:

    q = self.session.query(self.ClientProduct)
    q = q.options(joinedload_all(A.b, B.c))
#    q = q.options(joinedload_all(
#        A.client.of_type(PersonalClient),
#        PersonalClient.person)
#    )
    q = q.outerjoin(
        A.client.of_type(PersonalClient),
        PersonalClient.person
    )
    q = q.options(
        contains_eager(A.client),
        contains_eager(A.client, PersonalClient.person)
    )

It fails with:

Traceback (most recent call last):
  File "/usr/lib/python2.7/unittest/case.py", line 327, in run
    testMethod()
  File "/usr/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/lada/mine/devel/python/ZFP/zfp/tests/model/test_joinedload.py",
line 96, in test_joinedload
    q = q.options(contains_eager(A.client), contains_eager(A.client,
PersonalClient.person))
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 1026, in
options
    return self._options(False, *args)
  File "<string>", line 1, in <lambda>
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 50, in
generate
    fn(self, *args[1:], **kw)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/query.py", line 1043, in
_options
    opt.process_query(self)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/interfaces.py", line
411, in process_query
    self._process(query, True)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/interfaces.py", line
419, in _process
    self.process_query_property(query, paths, mappers)
  File "/usr/lib/python2.7/dist-packages/sqlalchemy/orm/strategies.py", line
1405, in process_query_property
    prop = root_mapper._props[propname]
KeyError: 'person'

I am not sure if it is the query you have in mind (I still have to study the
option contains_eager).


Ladislav Lenart


On 24.9.2012 18:31, Michael Bayer wrote:
> 
> On Sep 24, 2012, at 12:06 PM, Ladislav Lenart wrote:
> 
>> Hello.
>>
>> Suppose the following example query
>>
>>    q = session.query(A)
>>    q = q.options(joinedload_all(A.b, B.c, C.d)
>>    q = q.otions(joinedload_all(A.client, PersonalClient.person)
>>    return q
>>
>> where
>>
>>    A has
>>        b_id FK to b(id)
>>        client_id FK to client(id)
>>    B has
>>        c_id FK to c(id)
>>    C has
>>        d_id FK to d(id)
>>    Client is a root of joined table inheritance
>>    PersonalClient is Client's subtype which adds
>>        person_id FK to person(id)
>>    Person has personal information (such as name and address).
>>
>> The above query does not work: personal information is not loaded eagerly 
>> but on
>> each access. How should I rewrite the joinedload options to make it work with
>> joined table inheritance?
> 
> you'd need to use 0.8, which has not yet had it's initial beta releases, then 
> options as follows:
> 
>       q.options(joinedload_all(A.client.of_type(PersonalClient), 
> PersonalClient.person))
> 
> for 0.7, you'd need to break this down more manually, and this *should* work:
> 
>       q.outerjoin(A.client.of_type(PersonalClient), 
> PersonalClient.person).options(contains_eager(A.client), 
> contains_eager(A.client, PersonalClient.person))
> 
> I'd be curious if either/both of these methods work without issue for you, as 
> this is a tricky one.
> 
> 


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