Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

composite primary key #6

Open
schmunk42 opened this Issue · 2 comments

2 participants

Tobias Munk bwx
Tobias Munk
Owner

When the primary key is composed of two columns, the command generation is also incorrect:

CREATE TABLE IF NOT EXISTS `alert_listener` (
  `alert_listener_id` int(11) NOT NULL AUTO_INCREMENT,
  `listener` varchar(250) DEFAULT NULL COMMENT 'Describes the listner (email address, phone number, ...).',
  `listener_type` int(11) DEFAULT NULL,
  `is_active` tinyint(1) DEFAULT NULL,
  `entity_alert_id` int(11) NOT NULL,
  PRIMARY KEY (`alert_listener_id`,`entity_alert_id`),
  KEY `fk_alert_listener_device_alert1` (`entity_alert_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=815 ;

gives

$this->createTable(AlertListener::model()->tableName(),
                array(
                        "alert_listener_id"=>"pk",
                        "listener"=>"varchar(250)",
                        "listener_type"=>"int(11)",
                        "is_active"=>"tinyint(1)",
                        "entity_alert_id"=>"int(11) NOT NULL",
                        "PRIMARY KEY (entity_alert_id)"
                ),
                $options);
bwx
bwx commented

I my case:
Table in sql:
CREATE TABLE IF NOT EXISTS AuthAssignment (
itemname varchar(64) NOT NULL,
userid varchar(64) NOT NULL,
bizrule text,
data text,
PRIMARY KEY (itemname,userid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

migrate code from you ext:
// Schema for table 'AuthAssignment'
$this->createTable("AuthAssignment",
array(
"itemname"=>"varchar(64) NOT NULL PRIMARY KEY",
"userid"=>"varchar(64) NOT NULL PRIMARY KEY",
"bizrule"=>"text",
"data"=>"text",
"PRIMARY KEY (itemname)"
),
$options);

var_dump:

for field itemname:
["isPrimaryKey"]=>
bool(true)
["isForeignKey"]=>
bool(true)

for field userid:
["isPrimaryKey"]=>
bool(true)
["isForeignKey"]=>
bool(false)

Then valid code that should be generated is:

$this->createTable("AuthAssignment",
array(
"itemname"=>"varchar(64) NOT NULL UNIQUE",
"userid"=>"varchar(64) NOT NULL",
"bizrule"=>"text",
"data"=>"text",
"PRIMARY KEY (itemname, userid)"
),
$options);

so algorithm will be like this (less or more): IF in THE SAME table present more than one ["isPrimaryKey"]=>TRUE
THEN
FIRST NOT NULL UNIQUE", SECOND "PRIMARY KEY (FIRS, SECOND)"

right ??
If yest could you make appropriate changes ?

regards bw

Tobias Munk
Owner

Sorry, I have no time at the moment to implement this feature, but feel free to send me a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.