Skip to content

Support primary keys that aren't named id #154

@Aesthetikx

Description

@Aesthetikx

I understand that when giving a order_by: column other than the default :id, extra care is required to ensure that unique results are accounted for because we cannot ensure that the user specified column is unique, and hence adding :id is required. However, I am thinking that the 'spirit' of this behavior is really not about :id specifically but about if we are sorting by the table's primary key or not. I have a few cases where unfortunately the table's primary key is not called :id, and in fact also does not even have a column named :id, and hence the 'more complex' sorting case is triggered and fails because there is no :id column.

I may or may not take a swing at this change if it seems worthwhile, but at a glance it seems that in Paginator something like order_by ||= :id could be replaced with order_by ||= relation.primary_key.to_sym, and then a few more spots also would have to be updated where we are relying on the behavior that the primary key is :id.

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