Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/activerecord-multi-tenant/model_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def partition_key

# Avoid primary_key errors when using composite primary keys (e.g. id, tenant_id)
def primary_key
# If receiver is an abstract class, it doesn't have a table_name
# In this case, we don't care about the primary key, so delegate to super
return super unless table_name

if defined?(PRIMARY_KEY_NOT_SET) ? !PRIMARY_KEY_NOT_SET.equal?(@primary_key) : @primary_key
return @primary_key
end
Expand All @@ -52,8 +56,7 @@ def primary_key

@primary_key = if primary_object_keys.size == 1
primary_object_keys.first
elsif table_name &&
connection.schema_cache.columns_hash(table_name).include?(DEFAULT_ID_FIELD)
elsif connection.schema_cache.columns_hash(table_name).include?(DEFAULT_ID_FIELD)
DEFAULT_ID_FIELD
end
end
Expand Down