Rails ERD supports several customisation options, all of which can be provided on the command line. Even if you're completely unhappy with the output, you can still use Rails ERD. It has a powerful API that you can use to inspect your domain models, or to easily generate output in the format of your choice.
attributes <type,...> | false
Specifies which attributes to include in the diagram output. This can be any
combination of the following attribute types:
- any foreign key column in use for associations
- the primary key column (typically id)
- any of the 'magic' timestamp columns (created_at/on, updated_at/on)
- the single table inheritance column (typically type)
- all other columns
disconnected true | false
- Specifies whether or not to display disconnected entities. An entity is disconnected if it has no relationships with any other entity. Default value: true
- The file basename of the generated diagram. Together with the file type, this will determine the file name of the output. Default value: ERD
filetype pdf | dot | ...
- The file type of the generated diagram. PDF output is strongly recommended, other formats may render significantly worse. The available formats depend on your installation of Graphviz. If you set the file type to dot, raw Graphviz instructions are saved in dot format. This does not require Graphviz to be installed. Default value: pdf
indirect true | false
- Specifies whether or not to display relationships that are indirect. Indirect relationships are defined in Active Record by has_many :through associations. Older versions of Graphviz may have trouble drawing diagrams with indirect relationships. Default value: false
inheritance true | false
- Specifies whether or not to display inheritance hierarchies. Single table inheritance in Rails is usually transparent and uninteresting in an entity-relationship diagram. In some cases inheritance is central to the domain model, however. For example, subtypes may have their own relationships, which would be hidden otherwise. In those cases it makes a lot of sense to display all subtypes. Default value: false
notation simple | bachman
The ideal diagram notation may not be the same for everyone. Rails ERD
defaults to simple arrows to indicate cardinalities. No difference is made
for optional and mandatory relationships (sometimes referred to as
participation). This a classic way to draw data structures. It is
easy to understand, and provides enough information in most cases.
If you prefer to see the cardinality as well as the participation, try setting this option to bachman. This is a more advanced notation, devised by Charles Bachman in 1992.
For notation examples, browse the gallery. Default value: simple
orientation horizontal | vertical
- Diagrams display entities in a hierarchical way. The hierarchy is defined by the associations on your models. A model that has_one or has_many other models will be higher in the hierarchy. This option causes the hierarchy to run either horizontally or vertically. Which of the two is most appropriate depends on your models, be sure to try both. Default value: horizontal
polymorphism true | false
- Specifies whether or not to display polymorphic hierarchies. Polymorphic associations are normally displayed as direct relationships. In some cases this may be confusing, because it masks their true nature. Enable this option if polymorphic associations play a crucial role in your domain model. Enabling this option will also display abstract classes. Default value: false
title true | false | <string>
- By default, a title is displayed at the top of the diagram: "<application> domain model". You can change the title by setting this option. If set to false, no title will be displayed at all. Default value: true
warn true | false
- When set to false, no warnings are printed to the command line while processing models and drawing the diagram. Default value: true
- Only include specified models. Together with exclude, this will allow to filter out models on your diagram. Default value: nil. Example: only="Order,Customer,Product"
- Exclude specified models. Together with only, this will allow to filter out models on your diagram. Default value: nil. Example: exclude="User,Role"
Rails ERD provides an abstract class that you can use to implement your own diagram generation code. The following example generates code that can be used with yUML, an online UML diagram service...
Only 14 lines of code! Then, simply call...
Rails ERD allows you to use its internal API to inspect your domain model. We give some examples here, but for a complete and up-to-date reference, please see the API documentation.
Suppose we have the following domain model...
We can use Rails ERD to discover some attributes of our domain model.