TabularEditor / BestPracticeRules

An official collection of standard Rules for use with Tabular Editor's Best Practice Analyzer.
122 stars 53 forks source link

[Rule Submit] META: Foreign Keys & Primary Keys should have the same name #15

Closed Gezahegne closed 4 years ago

Gezahegne commented 7 years ago
"ID": "META:_FOREIGN_KEYS_&_PRIMARY_KEYS_HAVE_THE_SAME_NAME",
"Name": "META: Foreign Keys & Primary Keys should have the same name",
"Category": null,
"Description": "Foreign Keys & Primary Keys should have the same name.",
"Severity": 3,
"Scope": "Relationship",
"ScopeString": "Relationships",
"Expression": "!FromColumn.Name.ToLower().Equals(ToColumn.Name.ToLower())",
"FixExpression": null,
"Compatibility": null,
"IsValid": false
otykier commented 6 years ago

I agree that in general, naming conventions should be in place to make sure that FK / PK columns are similarly named. However, there may be cases (such as role-playing dimensions), where it will not be possible to use the same names. An alternative suggestion could be that a FK column should at least end with the name of the PK key:

'Date'[DateKey] (PK) 'Sales'[OrderDateKey] (FK) 'Sales'[DueDateKey] (FK)

chaiwa-berian commented 4 years ago

@otykier I agree with you, I am working with data from CommCare which has cases and every case has a caseid column as a primary key which maybe a foreign key in a child case. So in the child case, the foreign key(caseid of the parent) is named indices_ and this rule fails! We cannot name the foreign key as caseid, in the child case, since the child case also has a primary key named caseid, resulting into name conflicts. So tweaking the rule to something like what @otykier recommended would be more helpful.