Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency of Schema::getTableForeignKeys() #740

Closed
arogachev opened this issue Aug 13, 2023 · 2 comments
Closed

Inconsistency of Schema::getTableForeignKeys() #740

arogachev opened this issue Aug 13, 2023 · 2 comments

Comments

@arogachev
Copy link
Contributor

SQL:

https://github.com/yiisoft/rbac-db/blob/518a74539b7f689d62c9023d33dc03540e042490/sql/sqlite-up.sql#L10-L16

CREATE TABLE `auth_item_child` (
  `parent` varchar(128) NOT NULL,
  `child` varchar(128) NOT NULL,
  PRIMARY KEY (`parent`, `child`),
  FOREIGN KEY (`parent`) REFERENCES `auth_item` (`name`),
  FOREIGN KEY (`child`) REFERENCES `auth_item` (`name`)
);

Result for SQLite:

array(1) {
  [0]=>
  object(Yiisoft\Db\Constraint\ForeignKeyConstraint)#5322 (7) {
    ["columnNames":"Yiisoft\Db\Constraint\Constraint":private]=>
    array(2) {
      [0]=>
      string(5) "child"
      [1]=>
      string(6) "parent"
    }
    ["name":"Yiisoft\Db\Constraint\Constraint":private]=>
    NULL
    ["foreignSchemaName":"Yiisoft\Db\Constraint\ForeignKeyConstraint":private]=>
    NULL
    ["foreignTableName":"Yiisoft\Db\Constraint\ForeignKeyConstraint":private]=>
    string(9) "auth_item"
    ["foreignColumnNames":"Yiisoft\Db\Constraint\ForeignKeyConstraint":private]=>
    array(2) {
      [0]=>
      string(4) "name"
      [1]=>
      string(4) "name"
    }
    ["onUpdate":"Yiisoft\Db\Constraint\ForeignKeyConstraint":private]=>
    string(9) "NO ACTION"
    ["onDelete":"Yiisoft\Db\Constraint\ForeignKeyConstraint":private]=>
    string(9) "NO ACTION"
  }
}

Result for MS SQL:

array(2) {
  [0]=>
  object(Yiisoft\Db\Constraint\ForeignKeyConstraint)#4603 (7) {
    ["foreignSchemaName":"Yiisoft\Db\Constraint\ForeignKeyConstraint":private]=>
    string(3) "dbo"
    ["foreignTableName":"Yiisoft\Db\Constraint\ForeignKeyConstraint":private]=>
    string(9) "auth_item"
    ["foreignColumnNames":"Yiisoft\Db\Constraint\ForeignKeyConstraint":private]=>
    array(1) {
      [0]=>
      string(4) "name"
    }
    ["onUpdate":"Yiisoft\Db\Constraint\ForeignKeyConstraint":private]=>
    string(8) "NOACTION"
    ["onDelete":"Yiisoft\Db\Constraint\ForeignKeyConstraint":private]=>
    string(8) "NOACTION"
    ["columnNames":"Yiisoft\Db\Constraint\Constraint":private]=>
    array(1) {
      [0]=>
      string(6) "parent"
    }
    ["name":"Yiisoft\Db\Constraint\Constraint":private]=>
    string(30) "FK__auth_item__paren__72C60C4A"
  }
  [1]=>
  object(Yiisoft\Db\Constraint\ForeignKeyConstraint)#4601 (7) {
    ["foreignSchemaName":"Yiisoft\Db\Constraint\ForeignKeyConstraint":private]=>
    string(3) "dbo"
    ["foreignTableName":"Yiisoft\Db\Constraint\ForeignKeyConstraint":private]=>
    string(9) "auth_item"
    ["foreignColumnNames":"Yiisoft\Db\Constraint\ForeignKeyConstraint":private]=>
    array(1) {
      [0]=>
      string(4) "name"
    }
    ["onUpdate":"Yiisoft\Db\Constraint\ForeignKeyConstraint":private]=>
    string(8) "NOACTION"
    ["onDelete":"Yiisoft\Db\Constraint\ForeignKeyConstraint":private]=>
    string(8) "NOACTION"
    ["columnNames":"Yiisoft\Db\Constraint\Constraint":private]=>
    array(1) {
      [0]=>
      string(5) "child"
    }
    ["name":"Yiisoft\Db\Constraint\Constraint":private]=>
    string(30) "FK__auth_item__child__73BA3083"
  }
}

For other RDBMS it's similar. Note the amount of foreign key constraints and organization of data (cokumnNames property). Other properties can be ignored within the context of this issue.

@Tigrov
Copy link
Member

Tigrov commented Aug 22, 2023

Is it solved by yiisoft/db-sqlite#268?

@arogachev
Copy link
Contributor Author

Yes, now it works as expected. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants