On Apr 6, 12:09 am, Matt Hoskins <skaffe...@googlemail.com> wrote:
> My apologies for reposting this - I originally posted this at the end
> of January and as soon as I posted it I realised that with the push
> for bug squashing for the 1.3 release going on I probably wouldn't get
> any attention (and thus comment or replies :), so I'm trying a repost
> now that 1.3 is out. If someone knowledgeable about the query code in
> django could comment on whether the behaviour is by design or an
> oversight that would be useful!
>
> (Below where I say "reverse name" I mean using that reverse name from
> the model that the OneToOneField relates to)
> ---------
> Working on some code I've hit that the reverse name for a
> OneToOneField cannot be used, it seems, in values_list or values. I
> couldn't see why there would need to be such an exclusion, given it is
> a one-to-one relationship, so am wondering if it's just an oversight
> in the code or a deliberate exclusion?
>
> The portion of code that is rejecting doing e.g.
> "values_list('onetoonereversename')" is in setup_joins where the if
> line reads:
>
>             if not allow_many and (m2m or not direct):
>
> The values of "m2m" and "direct" come from opts.get_field_by_name and
> it seems that the reverse of a OneToOne gives the same results as the
> reverse of a ForeignKey, as of course both are not m2m and are not
> direct. Looking at the code later on in setup_joins it describes the
> path where direct is false and m2m is false as being "One-to-many
> field (ForeignKey defined on the target model)", so it looks like the
> logic I've quoted above of "if not allow_many and (m2m or not direct)"
> has the "not direct" clause in to reject reverse ForeignKey
> relationships and in doing so also rejects reverse OneToOne
> relationships (and with the latter case I suspect it need not!).
>
> If someone a bit more knowledgeable about the query machinery could
> comment on whether it does look like an oversight or is a deliberate
> exclusion, then if it's the former I'll log it as a bug.
>
> Assuming the rest of the code is ok in the case of a reverse OneToOne
> then something along the lines of "if not allow_many and (m2m or (not
> direct and not isinstance(getattr(field,'field',None),OneToOneField))"
> instead could work to allow OneToOne reverses through in setup_joins
> when allow_many is False.
>
> Regards,
> Matt

Hi Matt,

Do you think this could be related to http://code.djangoproject.com/ticket/11448
?

If so, do the patches attached to that ticket help resolve your issue?

Thanks,

Julien

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to