voormedia / rails-erd

Generate Entity-Relationship Diagrams for Rails applications
http://voormedia.github.io/rails-erd/
MIT License
3.99k stars 365 forks source link

many through seems have a bug #309

Open williamhatch opened 5 years ago

williamhatch commented 5 years ago

and I read the code, here might have an issue: (relationship.rb)

ef initialize(domain, associations) # @private :nodoc:
        @domain = domain
        @reverse_associations, @forward_associations = partition_associations(associations)

        assoc = @forward_associations.first || @reverse_associations.first
        @source      = @domain.entity_by_name(self.class.send(:association_owner, assoc))
        @destination = @domain.entity_by_name(self.class.send(:association_target, assoc))
        @source, @destination = @destination, @source if assoc.belongs_to?
      end

@forward_associations.first || @reverse_associations.first

if @forward_associations or @reverse_associations more than 1 (like 2) would have a problem.

If i use indirect option I found only one direction arrow shown not 2-directions arrow shown. But it should 2-directions arrow show.

kerrizor commented 5 years ago

Thanks for opening an issue. Is this on an app you can share, or could you provide a mock version of the models and their relationships for me so I can try to reproduce this?

schmijos commented 4 years ago

I guess my issue is related:

class FilterDimension < ApplicationRecord
  has_many :filters
  has_many :filter_choices
  has_many :filter_ranges
end

class FilterChoice < ApplicationRecord
  belongs_to :filter_dimension
end

class FilterRange < ApplicationRecord
  belongs_to :filter_dimension
end

class Filter < ApplicationRecord
  belongs_to :filter_dimension
  has_many :filter_choices, through: :filter_dimension
  has_many :filter_ranges, through: :filter_dimension
end

This ends up with one dotted arrow only (the arrow from Filter to FilterRange is missing):

image