Skip to content

Commit

Permalink
Fix problem with setting up reflection with symbol values
Browse files Browse the repository at this point in the history
  • Loading branch information
crashtech committed Mar 22, 2024
1 parent 0f2ea69 commit f40f085
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ def association_class
end

def foreign_key
@foreign_key ||= options[:foreign_key] || derive_foreign_key.freeze
@foreign_key ||= options[:foreign_key]&.to_s || derive_foreign_key.freeze
end

def association_foreign_key
@association_foreign_key ||= foreign_key
end

def active_record_primary_key
@active_record_primary_key ||= options[:primary_key] || derive_primary_key
@active_record_primary_key ||= options[:primary_key]&.to_s || derive_primary_key
end

def join_primary_key(*)
Expand Down
2 changes: 1 addition & 1 deletion lib/torque/postgresql/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Torque
module PostgreSQL
VERSION = '2.4.3'
VERSION = '2.4.4'
end
end
8 changes: 8 additions & 0 deletions spec/tests/belongs_to_many_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@

model.belongs_to_many(:tests)
end

it 'allows setting up foreign key and primary_key as symbol' do
model.belongs_to_many(:tests, foreign_key: :test_ids, primary_key: :test_id)

reflection = model._reflections['tests']
expect(reflection.foreign_key).to be_eql('test_ids')
expect(reflection.active_record_primary_key).to be_eql('test_id')
end
end

context 'on association' do
Expand Down

0 comments on commit f40f085

Please sign in to comment.