Skip to content

Commit

Permalink
Override scope_for_create in Rails 6.1.3+
Browse files Browse the repository at this point in the history
In rails/rails#41319 the `scope_for_create` method was changed so that
it called `where_clause.to_h` directly and now bypasses the patched
version of `where_values_hash`. This means we now have to override
`scope_for_create` in Rails 6.1.3 and later.

Fixes globalize#776
  • Loading branch information
pixeltrix committed May 12, 2021
1 parent 541759f commit b4268ff
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/patches/active_record/relation.rb
@@ -1,12 +1,19 @@
if ::ActiveRecord::VERSION::STRING >= "5.0.0"
if ::ActiveRecord.version >= Gem::Version.new("5.0.0")
module Globalize
module Relation
def where_values_hash(relation_table_name = table_name)
return super unless respond_to?(:translations_table_name)
super.merge(super(translations_table_name))
end

if ::ActiveRecord.version >= Gem::Version.new("6.1.3")
def scope_for_create
return super unless respond_to?(:translations_table_name)
super.merge(where_values_hash(translations_table_name))
end
end
end
end

ActiveRecord::Relation.prepend Globalize::Relation
end
end

0 comments on commit b4268ff

Please sign in to comment.