friendly_id icon indicating copy to clipboard operation
friendly_id copied to clipboard

History module is not compatible with using uuid as ids

Open such opened this issue 3 years ago • 1 comments

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
        }

such avatar Mar 23 '21 14:03 such

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[bot] avatar Jun 16 '21 02:06 stale[bot]