Skip to content

Commit

Permalink
allow compound foreign keys
Browse files Browse the repository at this point in the history
  • Loading branch information
mival authored and shioyama committed Mar 20, 2024
1 parent 05c2f27 commit c014e86
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/mobility/backends/active_record/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ def configure(options)
options[:association_name] = :translations
options[:subclass_name] ||= :Translation
end
%i[foreign_key association_name subclass_name table_name].each { |key| options[key] = options[key].to_sym }
%i[foreign_key association_name subclass_name table_name].each { |key|
if options[key].is_a?(Array)
options[key] = options[key].map!(&:to_sym)
else
options[key] = options[key].to_sym
end
}
end
# @!endgroup

Expand Down
5 changes: 5 additions & 0 deletions spec/mobility/backends/active_record/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@
backend_class.configure(options)
expect(options[:foreign_key]).to eq(:article_id)
end

it "sets composite foreign_key" do
backend_class.configure(options)
expect(options[:foreign_key]).to eq([:article_id, :article_type])
end
end

describe "with query plugin" do
Expand Down

0 comments on commit c014e86

Please sign in to comment.