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

Scope is not applied for new records when history module is enabled #28

Open
sramos opened this issue Jul 3, 2020 · 0 comments
Open

Comments

@sramos
Copy link

sramos commented Jul 3, 2020

For globalized slugs, when both modules are enabled, scope and history, scope is not applied for new records, only for updated ones.

You can reproduce it creating two records with the same values excepting scoped data. Slug should be the same for both, but it doesn't. To let the same value, you have to modify translated slug with the same value of first record.

I think that the problem could be in the scope_for_slug_generator method of the history module version provided for this gem. Only when record exists the scope is used to get the slug table relationship.

Changing the order of friendly_id_config.uses?(:scoped) condition all works fine and slug is generated correctly:

@@ -109,12 +109,11 @@ method.
     # used slug.
     def scope_for_slug_generator
       relation = super
-      return relation if new_record?
-      relation = relation.merge(Slug.where('sluggable_id <> ?', id))
       if friendly_id_config.uses?(:scoped)
         relation = relation.where(Slug.arel_table[:scope].eq(serialized_scope))
       end
-      relation
+      relation = relation.merge(Slug.where('sluggable_id <> ?', id)) unless new_record?
+      return relation
     end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant