Hi Gilad,

The `parent_link` option can only be used if the model the o2o field is 
pointing to is a direct base of the model it's attached to. From what I 
understand `select_related` simply ignores `parent_link` fields since it 
assumes it's pointing to a MTI parent table which are JOINed by default 
(unless values() and friends are involved).

Django should warn you about this. Please file a new bug ticket 
<https://code.djangoproject.com/newticket> so we don't loose track of this 
issue.

Thanks!
Simon

Le samedi 14 novembre 2015 08:03:56 UTC-5, Gilad a écrit :
>
> Hi,
> Using Django 1.8.3, I have 2 models, both unmanaged (remote DB managed by 
> another system), with something similar to that:
>
> class Parent(Model):
> ... some fields...
>
> class Child(Model):
> id = OneToOneField(primary_key=True, parent_link=True)
> ... some other fields ...
>
> Notes:
>
>    1. Parent is not abstract.
>    2. Each of the models have their own real tables.
>    3. Not using model inheritance because I want the parent_link field to 
>    be called "id" (as the db column), and Django doesn't allow hiding fields 
>    (with the same name).
>
> Given all that, using select_related('id') in a Child QuerySet doesn't 
> work (no exception but the Parent fields aren't fetched in the same DB 
> query).
> In order to workaround the issue, I removed the parent_link attribute 
> (note that as the tables are unmanaged, this attribute, and others, exist 
> merely as documentation, so I can remove it).
> Without the parent_link attribute, the Child fields are indeed fetched in 
> the same DB query, as expected from select_related().
>
> Is it a bug in Django or something I'm missing?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3295081a-19f9-4607-b883-55ed0714ac68%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to