Skip to content

primary_key method returns column Identity property instead of primary property #454

@marceloeloelo

Description

@marceloeloelo

ActiveRecord::ConnectionAdapters::SQLServerAdapter#primary_key (link to method) is performing a lookup on the table's Identity column first and falling back to the Primary column later, only if it can't find the Identity one.

I wonder why we are taking that approach instead of making the look up on the Primary column first.

There are scenarios where the PK column for a table is not the same as the Identity column. In that case, the primary_key method is returning the wrong value. At least I would expect it to return the Primary and not the Identity.

From Microsoft SQL server doc:

Identity columns are commonly used in conjunction with PRIMARY KEY constraints to serve as the unique row identifier for the table.

It's not restrictive, they can be used in conjunction but not necessarily in every case, so I think we should change it to be more consistent with the real definition.

Can anyone share thoughts on this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions