preston / railroady

Ruby on Rails 3/4/5 model and controller UML class diagram generator. (`brew/port/apt-get install graphviz` before use!)
Other
1.72k stars 142 forks source link

Visualize belongs_to association following official Rails doc #95

Closed jolks closed 8 years ago

jolks commented 9 years ago

Activated with existing switch --show-belongs_to e.g. $ railroady -a --show-belongs_to -M | dot -Tpng > full_models.png

We can also add new related tasks to railroady.rake.

preston commented 9 years ago

Hi @jolks,

What does this change, exactly?

jolks commented 9 years ago

Hi @preston,

Previously, in railroady/models_diagram.rb, the macro == 'belongs_to' would go to ELSE block in IF-ELSE block at line 298. Hence, belongs_to would have assoc_type = 'many-many'.

The DOT graph edge for assoc_type = 'many-many' in railroady/diagram_graph.rb is arrowtail=crow, arrowhead=crow at line 125. In other words, previously, the macro == 'belongs_to' will appear as: ->------<-

Unfortunately belongs_to does not really equate to many-many based on http://guides.rubyonrails.org/association_basics.html#belongs-to-association-reference vs. http://guides.rubyonrails.org/association_basics.html#has-and-belongs-to-many-association-reference.

Therefore this change is to differentiate the belongs_to from many-many in which belongs_to DOT graph edge is set to appear as: -------->

This change is very helpful for Rails project with many models consisting of multiple belongs_to and many-many associations. Keeping track of them will be difficult if both associations appear the same.

preston commented 9 years ago

Ok, I'll check it out!

jolks commented 9 years ago

Cool, let me know if there is any concern or changes that I should do.

preston commented 8 years ago

Done! Will be in v1.4.0. Sorry for the lame long delay.

jolks commented 8 years ago

No worries, thanks for the merge and release!