Skip to content

Commit f40f085

Browse files
committed
Fix problem with setting up reflection with symbol values
1 parent 0f2ea69 commit f40f085

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

lib/torque/postgresql/reflection/belongs_to_many_reflection.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ def association_class
2525
end
2626

2727
def foreign_key
28-
@foreign_key ||= options[:foreign_key] || derive_foreign_key.freeze
28+
@foreign_key ||= options[:foreign_key]&.to_s || derive_foreign_key.freeze
2929
end
3030

3131
def association_foreign_key
3232
@association_foreign_key ||= foreign_key
3333
end
3434

3535
def active_record_primary_key
36-
@active_record_primary_key ||= options[:primary_key] || derive_primary_key
36+
@active_record_primary_key ||= options[:primary_key]&.to_s || derive_primary_key
3737
end
3838

3939
def join_primary_key(*)

lib/torque/postgresql/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module Torque
44
module PostgreSQL
5-
VERSION = '2.4.3'
5+
VERSION = '2.4.4'
66
end
77
end

spec/tests/belongs_to_many_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020

2121
model.belongs_to_many(:tests)
2222
end
23+
24+
it 'allows setting up foreign key and primary_key as symbol' do
25+
model.belongs_to_many(:tests, foreign_key: :test_ids, primary_key: :test_id)
26+
27+
reflection = model._reflections['tests']
28+
expect(reflection.foreign_key).to be_eql('test_ids')
29+
expect(reflection.active_record_primary_key).to be_eql('test_id')
30+
end
2331
end
2432

2533
context 'on association' do

0 commit comments

Comments
 (0)