From 48f33bc5804648802d3262701d7ed2e7d54b02e6 Mon Sep 17 00:00:00 2001 From: Julie GUO Date: Fri, 30 Jun 2023 15:48:06 +0200 Subject: [PATCH] [403] Allows foreign key to_sym on Array --- lib/rails_erd/domain/attribute.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/rails_erd/domain/attribute.rb b/lib/rails_erd/domain/attribute.rb index ac02dae..6d51dd5 100644 --- a/lib/rails_erd/domain/attribute.rb +++ b/lib/rails_erd/domain/attribute.rb @@ -77,9 +77,18 @@ def primary_key? # Returns +true+ if this attribute is used as a foreign key for any # relationship. def foreign_key? - @domain.relationships_by_entity_name(@model.name).map(&:associations).flatten.map { |associaton| - associaton.send(Domain.foreign_key_method_name).to_sym - }.include?(name.to_sym) + @domain + .relationships_by_entity_name(@model.name) + .map(&:associations) + .flatten + .map do |associaton| + result = associaton.send(Domain.foreign_key_method_name) + if result.class == Array + result.join("_").to_sym + else + result.to_sym + end + end.include?(name.to_sym) end # Returns +true+ if this attribute is used for single table inheritance.