Skip to content

Commit

Permalink
Fix uninitialized constant X::ActiveRecord::VERSION (#42)
Browse files Browse the repository at this point in the history
When the class that calls `multi_tenant` has another ActiveRecord class included, then this reference may resolve to the wrong ActiveRecord class. Make sure that does not happen by using ::ActiveRecord.

This happened for example if activerecord-multi-tenant and mobility gem were used in the same project.
  • Loading branch information
vollnhals authored and lfittl committed Jun 26, 2018
1 parent 4627830 commit c4747ad
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/activerecord-multi-tenant/model_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def partition_key
# Avoid primary_key errors when using composite primary keys (e.g. id, tenant_id)
def primary_key
return @primary_key if @primary_key
return @primary_key = super || DEFAULT_ID_FIELD if ActiveRecord::VERSION::MAJOR < 5
return @primary_key = super || DEFAULT_ID_FIELD if ::ActiveRecord::VERSION::MAJOR < 5

primary_object_keys = Array.wrap(connection.schema_cache.primary_keys(table_name)) - [partition_key]
if primary_object_keys.size == 1
Expand Down

0 comments on commit c4747ad

Please sign in to comment.