Code

Opened 3 years ago

Closed 3 years ago

Last modified 17 months ago

#15123 closed (invalid)

models Meta's db_table and ManyToManyField

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

Description

Given both models as follows:

class P(AuditModel):
    description = models.CharField(max_length=50, unique=True)

    class Meta:
        db_table = 'P'

class XSummary(AuditModel):
    p = models.ManyToManyField(P, blank = True, null = True, ) 
    
    class Meta:
        db_table = 'Summary'

The 2 models with cutomized db_table name will generate a relationship table as follows:

CREATE TABLE "SUMMARY_P" (
    "ID" NUMBER(11) NOT NULL PRIMARY KEY,
    "XSUMMARY_ID" NUMBER(11) NOT NULL,
    "P_ID" NUMBER(11) NOT NULL REFERENCES "P" ("ID") DEFERRABLE INITIALLY DEFERRED,
)
;

Now you can see that the table name "SUMMARY_P" combined the cutomized db_table name of both models. But the field "XSUMMARY_ID" still take the mode name -- "XSUMMARY", not the db_table "SUMMARY". Franckly, I would like to have the field "XSUMMARY_ID" as "field "SUMMARY_ID".

Any feedback or fix on the issue ?

Attachments (0)

Change History (3)

comment:1 Changed 3 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

This can be achieved by defining a custom m2m-through model, and defining the db_column attribute on the FK fields.

comment:2 Changed 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

comment:3 Changed 17 months ago by akaariai

  • Component changed from ORM aggregation to Database layer (models, ORM)

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.