On 12/03/2010 03:06 PM, Jonas H. wrote:
On 12/03/2010 10:04 AM, Waldemar Kornewald wrote:
You probably don't want to use those aliases. Instead, you should use
a separate alias namespace for
embedded object filters. Otherwise you'll have to deal with the
complex JOIN code in the backend unnecessary. Aliases for embedded
objects could just be simple integers that get incremented for each
field independently with each new filter() call that mentions the
respective field.

Well that's where I'm stuck. I have no idea about how I could know in
the `add_filter` method, called from `add_q` for every filter, whether
the filters already added to the where clause come from the same
`.filter` call or from another.

So I did something I'd call "code guessing" and finally got a working solution, although I'm not sure it breaks anything... could someone tell me whether it does?

diff -r a632a02c9ff2 django/db/models/sql/query.py
[snip]
@@ -1022,6 +1023,13 @@
field, target, opts, join_list, last, extra_filters = self.setup_joins(
              parts, opts, alias, True, allow_many, can_reuse=can_reuse,
              negate=negate, process_extras=process_extras)
+ except PseudoJoin, e:
+     join = (alias, 'dummy', 'dummy', e.field.attname)
+     alias = self.join(join, reuse=can_reuse, always_create=True)
+     self.unref_alias(alias)
+     can_reuse.add(alias)
+     e.field.handle_join(self, parts, alias, lookup_type, value)
+     return
  except MultiJoin, e:
      self.split_exclude(filter_expr, LOOKUP_SEP.join(parts[:e.level]),
              can_reuse)
@@ -1333,6 +1341,8 @@
              self.update_dupe_avoidance(dupe_opts, dupe_col, alias)

  if pos != len(names) - 1:
+     if hasattr(field, 'handle_join'):
+         raise PseudoJoin(field)
      if pos == len(names) - 2:
raise FieldError("Join on field %r not permitted. Did you misspell %r for the lookup type?" % (name, names[pos + 1]))
      else:

--
You received this message because you are subscribed to the Google Groups "Django 
developers" group.
To post to this group, send email to django-develop...@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