Code

Opened 9 years ago

Closed 8 years ago

Last modified 7 years ago

#343 closed defect (fixed)

One-to-one relations - different primary_key

Reported by: Bless Owned by: adrian
Component: Metasystem Version: master
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: UI/UX:

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 (0)

Change History (5)

comment:1 Changed 9 years ago by adrian

  • Component changed from Core framework to Metasystem

comment:2 Changed 8 years ago by ubernostrum

  • Severity changed from major to normal
  • Version changed from 1.0 to SVN

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 Changed 8 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

Fixed in r3846.

comment:4 Changed 7 years ago 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.

comment:5 Changed 7 years ago by jacob

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

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.