Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle paper_trail's custom version classes. #304

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/rails_erd/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ def check_association_validity(association)
association.check_validity!

if association.options[:polymorphic]
entity_name = association.class_name
entity_by_name(entity_name) or raise "polymorphic interface #{entity_name} does not exist"
check_polymorphic_association_validity(association)
else
entity_name = association.klass.name # Raises NameError if the associated class cannot be found.
entity_by_name(entity_name) or raise "model #{entity_name} exists, but is not included in domain"
Expand All @@ -150,6 +149,14 @@ def check_association_validity(association)
warn "Ignoring invalid association #{association_description(association)} (#{e.message})"
end

def check_polymorphic_association_validity(association)
entity_name = association.class_name
entity = entity_by_name(entity_name)
if entity.nil? || entity.generalized?
raise "polymorphic interface #{entity_name} does not exist"
end
end

def association_description(association)
"#{association.name.inspect} on #{association.active_record}"
end
Expand Down