diff --git a/lib/active_record_shards/model.rb b/lib/active_record_shards/model.rb index 7d3c6581..97b43f5f 100644 --- a/lib/active_record_shards/model.rb +++ b/lib/active_record_shards/model.rb @@ -11,7 +11,11 @@ def not_sharded end def is_sharded? # rubocop:disable Naming/PredicateName - if self == ActiveRecord::Base + # "sharded" here means self.sharded, but actually writing "self.sharded" + # doesn't work until Ruby 2.7 (and this gem currently supports 2.6). + return sharded unless sharded.nil? + + self.sharded = if self == ActiveRecord::Base sharded != false && supports_sharding? elsif self == base_class if sharded.nil?