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

History module is not compatible with using uuid as ids #969

Open
such opened this issue Mar 23, 2021 · 1 comment
Open

History module is not compatible with using uuid as ids #969

such opened this issue Mar 23, 2021 · 1 comment
Labels

Comments

@such
Copy link

such commented Mar 23, 2021

When using uuids as id for the friendly_id_slugs table the history can be wrongly considered out of date.

I created the friendly_id_slugs table with create_table :friendly_id_slugs, id: :uuid.

In history.rb, the slugs relationship is defined as:

has_many :slugs, -> {order(id: :desc)}, **{
          :as         => :sluggable,
          :dependent  => @friendly_id_config.dependent_value,
          :class_name => Slug.to_s
        }

In order to find the current slug in history_is_up_to_date?, it uses: latest_history = slugs.first

ordering by id is not compatible with this when ids are uuids.

Potential solution:

Allowing configuration of the ordering key:

has_many :slugs, -> {order(@friendly_id_config.ordering_key => :desc)}, **{
          :as         => :sluggable,
          :dependent  => @friendly_id_config.dependent_value,
          :class_name => Slug.to_s
        }
@stale
Copy link

stale bot commented Jun 16, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 16, 2021
@parndt parndt added the pinned label Jun 22, 2021
@stale stale bot removed the stale label Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants