Django

Code

Ticket #343 (closed: fixed)

Opened 3 years ago

Last modified 1 year ago

One-to-one relations - different primary_key

Reported by: Bless Assigned to: adrian
Milestone: Component: Metasystem
Version: SVN Keywords: One-to-one
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

When is used a different primary_key (no integer) in One-to-one relations, id is always a integer

class Nic(meta.Model):
    fields = (
        meta.CharField('name', maxlength=4),
    )
class Network(meta.Model):
    fields = (
        meta.OneToOneField(nics.Nic),
        meta.CharField('name', maxlength=3, choices=NETWORK_TYPES, unique=True),
    )

BEGIN;
CREATE TABLE nics_nics (
    id integer NOT NULL PRIMARY KEY,
    name varchar(4) NOT NULL
);
CREATE TABLE nics_networks (
    id integer NOT NULL PRIMARY KEY REFERENCES nics_nics (id),
    name varchar(3) NOT NULL UNIQUE
);
COMMIT;

id integer NOT NULL PRIMARY KEY REFERENCES nics_nics (id), -> OK


class Nic(meta.Model):
    fields = (
        meta.CharField('name', maxlength=4, primary_key=True),
    )
class Network(meta.Model):
    fields = (
        meta.OneToOneField(nics.Nic),
        meta.CharField('name', maxlength=3, choices=NETWORK_TYPES, unique=True),
    )

BEGIN;
CREATE TABLE nics_nics (
    name varchar(4) NOT NULL PRIMARY KEY
);
CREATE TABLE nics_networks (
    id integer NOT NULL PRIMARY KEY REFERENCES nics_nics (name),
    name varchar(3) NOT NULL UNIQUE
);
COMMIT;

id integer NOT NULL PRIMARY KEY REFERENCES nics_nics (name), -> Bug
It should be varchar in this case.

Attachments

Change History

09/01/05 18:10:28 changed by adrian

  • component changed from Core framework to Metasystem.

08/27/06 00:13:11 changed by ubernostrum

  • version changed from 1.0 to SVN.
  • severity changed from major to normal.

The problem here is that OneToOneField inherits from IntegerField. Fixing it will require changing that, and the question is whether to inherit directly from Field as foreign keys do, or to inherit from ForeignKeyField (since that's what it ends up being in the DB).

09/26/06 07:58:23 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in r3846.

02/23/07 12:02:51 changed by jacob

(In [4558]) Fixed #343: filters that take strings now handle non-strings correctly. Thanks to Boffbowsh for the original patch, and to SmileyChris? for the updated patch and tests.

02/23/07 14:52:37 changed by jacob

(oops - shoulda said I fixed #393...)


Add/Change #343 (One-to-one relations - different primary_key)




Change Properties
Action