-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Error in a method findForeignKeys() of MS SQL schema #4813
Comments
I confirm. |
@o-rey can you confirm that the fix suggested is correct? |
Yes, at least for SQL Server 2014. For example, if I have a table
This leads to incorrect relations generated. Meanwhile the result of
which is correct. |
Do you have a chance to test older MSSQL? |
@samdark SQL 2008 confirmed. |
@o-rey thanks! I've created a pull request. Since I don't have proper MSSQL environment currently it would be great if you'll verify it's good to be merged. |
@samdark No, that's incorrect. Here's the correct query: SELECT
[kcu1].[column_name] AS [fk_column_name],
[kcu2].[table_name] AS [uq_table_name],
[kcu2].[column_name] AS [uq_column_name]
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS [rc]
JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS [kcu1] ON
[kcu1].[constraint_catalog] = [rc].[constraint_catalog] AND
[kcu1].[constraint_schema] = [rc].[constraint_schema] AND
[kcu1].[constraint_name] = [rc].[constraint_name]
JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS [kcu2] ON
[kcu2].[constraint_catalog] = [rc].[constraint_catalog] AND
[kcu2].[constraint_schema] = [rc].[constraint_schema] AND
[kcu2].[constraint_name] = [rc].[unique_constraint_name] AND
[kcu2].[ordinal_position] = [kcu1].[ordinal_position]
WHERE [kcu1].[table_name] = :tableName |
Fixed. Thanks for reporting and verifying it. |
In yii2/db/mssql/Schema.php on line 347 we see a [rc].[constraint_name]
This is a mistake.
Must be a [rc].[unique_constraint_name] for get a right foreign keys.
The text was updated successfully, but these errors were encountered: