diff --git a/lib/torque/postgresql/reflection/belongs_to_many_reflection.rb b/lib/torque/postgresql/reflection/belongs_to_many_reflection.rb index 5fe59b1..ad65e69 100644 --- a/lib/torque/postgresql/reflection/belongs_to_many_reflection.rb +++ b/lib/torque/postgresql/reflection/belongs_to_many_reflection.rb @@ -25,7 +25,7 @@ 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 @@ -33,7 +33,7 @@ def association_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(*) diff --git a/lib/torque/postgresql/version.rb b/lib/torque/postgresql/version.rb index dbe3fb9..309f276 100644 --- a/lib/torque/postgresql/version.rb +++ b/lib/torque/postgresql/version.rb @@ -2,6 +2,6 @@ module Torque module PostgreSQL - VERSION = '2.4.3' + VERSION = '2.4.4' end end diff --git a/spec/tests/belongs_to_many_spec.rb b/spec/tests/belongs_to_many_spec.rb index 8ddecbf..da02ca1 100644 --- a/spec/tests/belongs_to_many_spec.rb +++ b/spec/tests/belongs_to_many_spec.rb @@ -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