Howdy,

I originally posted about this issue on django-users here:
http://groups.google.com/group/django-users/browse_thread/thread/ca79f4cb085566a5
After further discussion of the issue on #django, I believe I have hit
upon a genuine bug in the Django ORM layer so I am posting here.

The following model renders correctly when viewed in the admin
interface:
class Cms_Consumer_Reports(models.Model):
    cms_consumer_reports_id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=765)
    description = models.TextField(blank=True)
    html = models.TextField(blank=True)
    html_title = models.TextField(blank=True)
    html_description = models.TextField(blank=True)
    html_keywords = models.TextField(blank=True)
    hidden = models.BooleanField()
    category = models.ManyToManyField('ontology.Category',
        db_table='map_cms_consumer_reports_to_category',
        verbose_name='Associated categories',
        help_text='Select all categories related to this report')
    right_column = models.TextField(blank=True)

Note that the generated SQL query for the ManyToManyField is correct,
in particular, it respects the db_table argument provided to the
ManyToManyField constructor:

SELECT `category`.`category_id`, `category`.`name`,
`category`.`description`, `category`.`group_label`,
`category`.`dw_id`, `category`.`ncat`
  FROM `category` INNER JOIN `map_cms_consumer_reports_to_category` ON
(`category`.`category_id` =
`map_cms_consumer_reports_to_category`.`category_id`) WHERE
`map_cms_consumer_reports_to_category`.`cms_consumer_reports_id` =
6868466

If, however, I add the following ForeignKey to the model, and attempt
to view it in the admin interface, it generates incorrect SQL for the
ManyToManyField:
    category_id = models.ForeignKey('ontology.Category',
        db_column='category_id',
        verbose_name='Ontology Category')

The incorrect SQL generated for the ManyToManyField follows.  Note
that it appears to ignore the db_table argument:
SELECT `category`.`category_id`, `category`.`name`,
`category`.`description`, `category`.`group_label`,
`category`.`dw_id`, `category`.`ncat`
  FROM `category` INNER JOIN `cms_consumer_reports` ON
(`category`.`category_id` = `cms_consumer_reports`.`category_id`)
WHERE `cms_consumer_reports`.`cms_consumer_reports_id` = 6868466

Any insights into this or assistance writing up a fix would be greatly
appreciated.

(Dan)

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