Opened 19 years ago

Closed 18 years ago

Last modified 18 years ago

#343 closed defect (fixed)

One-to-one relations - different primary_key

Reported by: Bless Owned by: Adrian Holovaty
Component: Metasystem Version: dev
Severity: normal Keywords: One-to-one
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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.

Change History (5)

comment:1 by Adrian Holovaty, 19 years ago

Component: Core frameworkMetasystem

comment:2 by James Bennett, 18 years ago

Severity: majornormal
Version: 1.0SVN

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).

comment:3 by Malcolm Tredinnick, 18 years ago

Resolution: fixed
Status: newclosed

Fixed in r3846.

comment:4 by Jacob, 18 years ago

(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.

comment:5 by Jacob, 18 years ago

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

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