Opened 16 years ago

Closed 16 years ago

#10628 closed (invalid)

RelatedManager and NULL

Reported by: anonymous Owned by: nobody
Component: Database layer (models, ORM) Version: 1.1-beta
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

My Model:

class Active(models.Model):
 post    = models.ForeignKey(Post, related_name='activeposts')
 rubrica = models.ForeignKey(Rubrica, related_name='activeposts', null=True, blank=True)
 type    = models.ForeignKey(Type, related_name='activeposts', null=True, blank=True)

Code:

>>> p = Post.objects.get(pk=1206535731)
>>> p.activeposts.filter(type__pk=2, rubrica__isnull=True)

return empty result. but a have data in database.

>>> p.activeposts.filter(type__exact=2, rubrica__isnull=True).query.as_sql()
('SELECT `doska_active`.`id`, `doska_active`.`post_id`, `doska_active`.`rubrica_id`, `doska_active`.`type_id` FROM `doska_active` LEFT OUTER JOIN `doska_rubrica` ON (`doska_active`.`rubrica_id` = `doska_rubrica`.`id`) WHERE (`doska_active`.`post_id` = %s  AND `doska_active`.`type_id` = %s  AND `doska_rubrica`.`id` IS NULL)', (1206535731, 2))

Problem in AND doska_rubrica.id IS NULL

Change History (4)

comment:1 by Malcolm Tredinnick, 16 years ago

Resolution: invalid
Status: newclosed

Your filter is asking for things where rubrica__isnull=True, which is why that comparison to NULL is in the query. That's the correct SQL for that filter.

comment:2 by anonymous, 16 years ago

I need:
AND doska_active.type_id = %s AND doska_active.rubrica_id IS NULL

comment:3 by anonymous, 16 years ago

Resolution: invalid
Status: closedreopened

comment:4 by Malcolm Tredinnick, 16 years ago

Resolution: invalid
Status: reopenedclosed

Please ask support questions on the django-users mailing list. The SQL output you are getting for the filter you have given is not incorrect. There is no bug here.

Note: See TracTickets for help on using tickets.
Back to Top