Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.2.2
-
Fix Version/s: None
-
Component/s: Import/Export
-
Labels:None
-
Environment:FreeBSD 6.1, Apache 2.2.4, PHP 5.3.2, MySQL 5.0.41
Description
When exporting my schema from yaml I noticed that some CONSTRAINT are not created, but all the models are. After analyzing the code I found that an issue is not related to YAML but is related to Doctrine_Table::getExportableFormat(). I have models creation option to create it in PEAR-like style.
So, when you have a schema like this:
----------------
Partner_Code:
tableName: partner_code
columns:
id:
type: integer(4)
unsigned: true
primary: true
autoincrement: true
notnull: true
code:
type: string(64)
unique: true
notnull: true
Partner_Channel:
tableName: partner_channel
columns:
id:
type: integer(4)
unsigned: true
primary: true
autoincrement: true
notnull: true
name:
type: string(64)
notnull: true
relations:
Codes:
class: Partner_Code
local: channel_id
foreign: code_id
refClass: Partner_Channel_Code
foreignAlias: Partner_Channel
foreignType: one
type: many
Partner_Channel_Code:
tableName: partner_channel_x_code
columns:
channel_id:
type: integer(4)
unsigned: true
primary: true
notnull: true
code_id:
type: integer(4)
unsigned: true
primary: true
notnull: true
----------------
it generates sql like this:
----------------
CREATE TABLE partner_channel (id INT UNSIGNED AUTO_INCREMENT, name VARCHAR(64) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB;
CREATE TABLE partner_channel_x_code (channel_id INT UNSIGNED, code_id INT UNSIGNED, PRIMARY KEY(channel_id, code_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB;
CREATE TABLE partner_code (id INT UNSIGNED AUTO_INCREMENT, code VARCHAR(64) NOT NULL UNIQUE, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB;
ALTER TABLE partner_channel_x_code ADD CONSTRAINT partner_channel_x_code_channel_id_partner_channel_id FOREIGN KEY (channel_id) REFERENCES partner_channel(id);
----------------
But should also generate:
----------------
ALTER TABLE partner_channel_x_code ADD CONSTRAINT partner_channel_x_code_code_id_partner_code_id FOREIGN KEY (code_id) REFERENCES partner_code(id);
----------------
But if I just change the schema with this changes (notice the Channel changed to Shannel):
----------------
Partner_Channel:
relations:
Codes:
refClass: Partner_Shannel_Code
Partner_Shannel_Code:
tableName: partner_channel_x_code
----------------
Everything is created.
----------------
CREATE TABLE partner_channel (id INT UNSIGNED AUTO_INCREMENT, name VARCHAR(64) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB;
CREATE TABLE partner_code (id INT UNSIGNED AUTO_INCREMENT, code VARCHAR(64) NOT NULL UNIQUE, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB;
CREATE TABLE partner_channel_x_code (channel_id INT UNSIGNED, code_id INT UNSIGNED, PRIMARY KEY(channel_id, code_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB;
ALTER TABLE partner_channel_x_code ADD CONSTRAINT partner_channel_x_code_code_id_partner_code_id FOREIGN KEY (code_id) REFERENCES partner_code(id);
ALTER TABLE partner_channel_x_code ADD CONSTRAINT partner_channel_x_code_channel_id_partner_channel_id FOREIGN KEY (channel_id) REFERENCES partner_channel(id);
----------------
So as I figured out is that when creating the tables alphabetic order has an influence on creating the CONSTRAINT for that Model in sql. I suppose line 715 of the Doctrine/Table.php near $key = $this->_checkForeignKeyExists(...) is operating, but I am not sure (when inserting into DB some tables are not created yet?).
Do not know how to markup here, it's my first issue in Jira, please press "edit" to see the yaml code formatted
Activity
| Field | Original Value | New Value |
|---|---|---|
| Description |
When exporting my schema from yaml I noticed that some CONSTRAINT are not created, but all the models are. After analyzing the code I found that an issue is not related to YAML but is related to Doctrine_Table::getExportableFormat(). I have models creation option to create it in PEAR-like style. So, when you have a schema like this: ---------------- Partner_Code: tableName: partner_code columns: id: type: integer(4) unsigned: true primary: true autoincrement: true notnull: true code: type: string(64) unique: true notnull: true Partner_Channel: tableName: partner_channel columns: id: type: integer(4) unsigned: true primary: true autoincrement: true notnull: true name: type: string(64) notnull: true relations: Codes: class: Partner_Code local: channel_id foreign: code_id refClass: Partner_Channel_Code foreignAlias: Partner_Channel foreignType: one type: many Partner_Channel_Code: tableName: partner_channel_x_code columns: channel_id: type: integer(4) unsigned: true primary: true notnull: true code_id: type: integer(4) unsigned: true primary: true notnull: true ---------------- it generates sql like this: ---------------- CREATE TABLE partner_channel (id INT UNSIGNED AUTO_INCREMENT, name VARCHAR(64) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; CREATE TABLE partner_channel_x_code (channel_id INT UNSIGNED, code_id INT UNSIGNED, PRIMARY KEY(channel_id, code_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; CREATE TABLE partner_code (id INT UNSIGNED AUTO_INCREMENT, code VARCHAR(64) NOT NULL UNIQUE, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; ALTER TABLE partner_channel_x_code ADD CONSTRAINT partner_channel_x_code_channel_id_partner_channel_id FOREIGN KEY (channel_id) REFERENCES partner_channel(id); ---------------- But should also generate: ---------------- ALTER TABLE partner_channel_x_code ADD CONSTRAINT partner_channel_x_code_channel_id_partner_channel_id FOREIGN KEY (channel_id) REFERENCES partner_channel(id); ---------------- But if I just change the schema with this changes (notice the Channel changed to Shannel): ---------------- Partner_Channel: relations: Codes: refClass: Partner_Shannel_Code Partner_Shannel_Code: tableName: partner_channel_x_code ---------------- Everything is created. ---------------- CREATE TABLE partner_channel (id INT UNSIGNED AUTO_INCREMENT, name VARCHAR(64) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; CREATE TABLE partner_code (id INT UNSIGNED AUTO_INCREMENT, code VARCHAR(64) NOT NULL UNIQUE, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; CREATE TABLE partner_channel_x_code (channel_id INT UNSIGNED, code_id INT UNSIGNED, PRIMARY KEY(channel_id, code_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; ALTER TABLE partner_channel_x_code ADD CONSTRAINT partner_channel_x_code_code_id_partner_code_id FOREIGN KEY (code_id) REFERENCES partner_code(id); ALTER TABLE partner_channel_x_code ADD CONSTRAINT partner_channel_x_code_channel_id_partner_channel_id FOREIGN KEY (channel_id) REFERENCES partner_channel(id); ---------------- So as I figured out is that when creating the tables alphabetic order has an influence on creating the CONSTRAINT for that Model in sql. I suppose line 715 of the Doctrine/Table.php near $key = $this->_checkForeignKeyExists(...) is operating, but I am not sure (when inserting into DB some tables are not created yet?). |
When exporting my schema from yaml I noticed that some CONSTRAINT are not created, but all the models are. After analyzing the code I found that an issue is not related to YAML but is related to Doctrine_Table::getExportableFormat(). I have models creation option to create it in PEAR-like style. So, when you have a schema like this: ---------------- Partner_Code: tableName: partner_code columns: id: type: integer(4) unsigned: true primary: true autoincrement: true notnull: true code: type: string(64) unique: true notnull: true Partner_Channel: tableName: partner_channel columns: id: type: integer(4) unsigned: true primary: true autoincrement: true notnull: true name: type: string(64) notnull: true relations: Codes: class: Partner_Code local: channel_id foreign: code_id refClass: Partner_Channel_Code foreignAlias: Partner_Channel foreignType: one type: many Partner_Channel_Code: tableName: partner_channel_x_code columns: channel_id: type: integer(4) unsigned: true primary: true notnull: true code_id: type: integer(4) unsigned: true primary: true notnull: true ---------------- it generates sql like this: ---------------- CREATE TABLE partner_channel (id INT UNSIGNED AUTO_INCREMENT, name VARCHAR(64) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; CREATE TABLE partner_channel_x_code (channel_id INT UNSIGNED, code_id INT UNSIGNED, PRIMARY KEY(channel_id, code_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; CREATE TABLE partner_code (id INT UNSIGNED AUTO_INCREMENT, code VARCHAR(64) NOT NULL UNIQUE, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; ALTER TABLE partner_channel_x_code ADD CONSTRAINT partner_channel_x_code_channel_id_partner_channel_id FOREIGN KEY (channel_id) REFERENCES partner_channel(id); ---------------- But should also generate: ---------------- ALTER TABLE partner_channel_x_code ADD CONSTRAINT partner_channel_x_code_channel_id_partner_channel_id FOREIGN KEY (channel_id) REFERENCES partner_channel(id); ---------------- But if I just change the schema with this changes (notice the Channel changed to Shannel): ---------------- Partner_Channel: relations: Codes: refClass: Partner_Shannel_Code Partner_Shannel_Code: tableName: partner_channel_x_code ---------------- Everything is created. ---------------- CREATE TABLE partner_channel (id INT UNSIGNED AUTO_INCREMENT, name VARCHAR(64) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; CREATE TABLE partner_code (id INT UNSIGNED AUTO_INCREMENT, code VARCHAR(64) NOT NULL UNIQUE, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; CREATE TABLE partner_channel_x_code (channel_id INT UNSIGNED, code_id INT UNSIGNED, PRIMARY KEY(channel_id, code_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; ALTER TABLE partner_channel_x_code ADD CONSTRAINT partner_channel_x_code_code_id_partner_code_id FOREIGN KEY (code_id) REFERENCES partner_code(id); ALTER TABLE partner_channel_x_code ADD CONSTRAINT partner_channel_x_code_channel_id_partner_channel_id FOREIGN KEY (channel_id) REFERENCES partner_channel(id); ---------------- So as I figured out is that when creating the tables alphabetic order has an influence on creating the CONSTRAINT for that Model in sql. I suppose line 715 of the Doctrine/Table.php near $key = $this->_checkForeignKeyExists(...) is operating, but I am not sure (when inserting into DB some tables are not created yet?). Do not know how to markup here, it's my first issue in Jira, please press "edit" to see the yaml code formatted |
| Description |
When exporting my schema from yaml I noticed that some CONSTRAINT are not created, but all the models are. After analyzing the code I found that an issue is not related to YAML but is related to Doctrine_Table::getExportableFormat(). I have models creation option to create it in PEAR-like style. So, when you have a schema like this: ---------------- Partner_Code: tableName: partner_code columns: id: type: integer(4) unsigned: true primary: true autoincrement: true notnull: true code: type: string(64) unique: true notnull: true Partner_Channel: tableName: partner_channel columns: id: type: integer(4) unsigned: true primary: true autoincrement: true notnull: true name: type: string(64) notnull: true relations: Codes: class: Partner_Code local: channel_id foreign: code_id refClass: Partner_Channel_Code foreignAlias: Partner_Channel foreignType: one type: many Partner_Channel_Code: tableName: partner_channel_x_code columns: channel_id: type: integer(4) unsigned: true primary: true notnull: true code_id: type: integer(4) unsigned: true primary: true notnull: true ---------------- it generates sql like this: ---------------- CREATE TABLE partner_channel (id INT UNSIGNED AUTO_INCREMENT, name VARCHAR(64) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; CREATE TABLE partner_channel_x_code (channel_id INT UNSIGNED, code_id INT UNSIGNED, PRIMARY KEY(channel_id, code_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; CREATE TABLE partner_code (id INT UNSIGNED AUTO_INCREMENT, code VARCHAR(64) NOT NULL UNIQUE, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; ALTER TABLE partner_channel_x_code ADD CONSTRAINT partner_channel_x_code_channel_id_partner_channel_id FOREIGN KEY (channel_id) REFERENCES partner_channel(id); ---------------- But should also generate: ---------------- ALTER TABLE partner_channel_x_code ADD CONSTRAINT partner_channel_x_code_channel_id_partner_channel_id FOREIGN KEY (channel_id) REFERENCES partner_channel(id); ---------------- But if I just change the schema with this changes (notice the Channel changed to Shannel): ---------------- Partner_Channel: relations: Codes: refClass: Partner_Shannel_Code Partner_Shannel_Code: tableName: partner_channel_x_code ---------------- Everything is created. ---------------- CREATE TABLE partner_channel (id INT UNSIGNED AUTO_INCREMENT, name VARCHAR(64) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; CREATE TABLE partner_code (id INT UNSIGNED AUTO_INCREMENT, code VARCHAR(64) NOT NULL UNIQUE, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; CREATE TABLE partner_channel_x_code (channel_id INT UNSIGNED, code_id INT UNSIGNED, PRIMARY KEY(channel_id, code_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; ALTER TABLE partner_channel_x_code ADD CONSTRAINT partner_channel_x_code_code_id_partner_code_id FOREIGN KEY (code_id) REFERENCES partner_code(id); ALTER TABLE partner_channel_x_code ADD CONSTRAINT partner_channel_x_code_channel_id_partner_channel_id FOREIGN KEY (channel_id) REFERENCES partner_channel(id); ---------------- So as I figured out is that when creating the tables alphabetic order has an influence on creating the CONSTRAINT for that Model in sql. I suppose line 715 of the Doctrine/Table.php near $key = $this->_checkForeignKeyExists(...) is operating, but I am not sure (when inserting into DB some tables are not created yet?). Do not know how to markup here, it's my first issue in Jira, please press "edit" to see the yaml code formatted |
When exporting my schema from yaml I noticed that some CONSTRAINT are not created, but all the models are. After analyzing the code I found that an issue is not related to YAML but is related to Doctrine_Table::getExportableFormat(). I have models creation option to create it in PEAR-like style. So, when you have a schema like this: ---------------- Partner_Code: tableName: partner_code columns: id: type: integer(4) unsigned: true primary: true autoincrement: true notnull: true code: type: string(64) unique: true notnull: true Partner_Channel: tableName: partner_channel columns: id: type: integer(4) unsigned: true primary: true autoincrement: true notnull: true name: type: string(64) notnull: true relations: Codes: class: Partner_Code local: channel_id foreign: code_id refClass: Partner_Channel_Code foreignAlias: Partner_Channel foreignType: one type: many Partner_Channel_Code: tableName: partner_channel_x_code columns: channel_id: type: integer(4) unsigned: true primary: true notnull: true code_id: type: integer(4) unsigned: true primary: true notnull: true ---------------- it generates sql like this: ---------------- CREATE TABLE partner_channel (id INT UNSIGNED AUTO_INCREMENT, name VARCHAR(64) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; CREATE TABLE partner_channel_x_code (channel_id INT UNSIGNED, code_id INT UNSIGNED, PRIMARY KEY(channel_id, code_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; CREATE TABLE partner_code (id INT UNSIGNED AUTO_INCREMENT, code VARCHAR(64) NOT NULL UNIQUE, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; ALTER TABLE partner_channel_x_code ADD CONSTRAINT partner_channel_x_code_channel_id_partner_channel_id FOREIGN KEY (channel_id) REFERENCES partner_channel(id); ---------------- But should also generate: ---------------- ALTER TABLE partner_channel_x_code ADD CONSTRAINT partner_channel_x_code_code_id_partner_code_id FOREIGN KEY (code_id) REFERENCES partner_code(id); ---------------- But if I just change the schema with this changes (notice the Channel changed to Shannel): ---------------- Partner_Channel: relations: Codes: refClass: Partner_Shannel_Code Partner_Shannel_Code: tableName: partner_channel_x_code ---------------- Everything is created. ---------------- CREATE TABLE partner_channel (id INT UNSIGNED AUTO_INCREMENT, name VARCHAR(64) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; CREATE TABLE partner_code (id INT UNSIGNED AUTO_INCREMENT, code VARCHAR(64) NOT NULL UNIQUE, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; CREATE TABLE partner_channel_x_code (channel_id INT UNSIGNED, code_id INT UNSIGNED, PRIMARY KEY(channel_id, code_id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = INNODB; ALTER TABLE partner_channel_x_code ADD CONSTRAINT partner_channel_x_code_code_id_partner_code_id FOREIGN KEY (code_id) REFERENCES partner_code(id); ALTER TABLE partner_channel_x_code ADD CONSTRAINT partner_channel_x_code_channel_id_partner_channel_id FOREIGN KEY (channel_id) REFERENCES partner_channel(id); ---------------- So as I figured out is that when creating the tables alphabetic order has an influence on creating the CONSTRAINT for that Model in sql. I suppose line 715 of the Doctrine/Table.php near $key = $this->_checkForeignKeyExists(...) is operating, but I am not sure (when inserting into DB some tables are not created yet?). Do not know how to markup here, it's my first issue in Jira, please press "edit" to see the yaml code formatted |