Skip to content

Commit

Permalink
Check that class responds to mobility_attribute?
Browse files Browse the repository at this point in the history
  • Loading branch information
shioyama committed Apr 26, 2021
1 parent 4c5c460 commit 9e46fb1
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/mobility/plugins/active_record/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ def where(opts = :chain, *rest)
end

def order(opts, *rest)
return super unless @klass.respond_to?(:mobility_attribute?)

case opts
when Symbol, String
@klass.mobility_attribute?(opts) ? order({ opts => :asc }, *rest) : super
Expand All @@ -161,6 +163,9 @@ def order(opts, *rest)
define_method method_name do |*attrs, &block|
return super(*attrs, &block) if (method_name == 'select' && block.present?)

if ::ActiveRecord::VERSION::STRING < '7.0'
return super(*attrs, &block) unless @klass.respond_to?(:mobility_attribute?)
end
return super(*attrs, &block) unless attrs.any?(&@klass.method(:mobility_attribute?))

keys = attrs.dup
Expand Down

0 comments on commit 9e46fb1

Please sign in to comment.