Browse this page to see some example diagrams. Many of them are generated from actual applications. Want to try for yourself? See the installation instructions. If you have a great example diagram of an open source Rails project that you wish to share, get in touch!
Refinery CMS
Refinery is a content management system for medium-sized websites. The model diagram generated by Rails ERD is particularly clean and convenient.
Gemcutter
The Rubygems website is powered by Gemcutter. This application maintains an overview of all available Ruby libraries that are packaged as gems.
Publify
Some models rely heavily on single table inheritance. Publify, a popular blogging application, uses single table inheritance for many of its most important models. To explicitly display all child models and their relationships, this diagram was generated with inheritance=true.
Spree
Slightly larger domain models may be difficult to comprehend, even when drawn in a diagram. Spree is an open-source e-commerce application with 60 models. If we hide the attributes, the diagram gives a clearer overview of the entities themselves. This diagram was generated with attributes=false.
Detailed examples
Now that we've seen some real entity-relationship diagrams, let's see what they're composed of exactly. We start with a single entity. Below is the database migration of a table named photographs, which could contain digital photographs and their metadata. Based on this database table, Rails ERD renders the Photograph entity with all relevant attributes and their types.
Now we take a look at the relationships that are possible in a model diagram. Consider the following two models, which describe countries and their heads of state. They are each associated with the other model, so they share a one-to-one relationship. It is rendered as follows...
Here's another example. One galleon (a medieval warship) has many cannons. If we model them in a database, they will share a one-to-many relationship. This cardinality is represented with a single arrow.
When drawing a many-to-many relationship, both ends are represented by an arrow.
Many-to-many relationships with a join model will be drawn together with this third model. The individual relationships are displayed as one-to-many relationships. The many-to-many relationship is indirect and will be drawn with a dotted line.
Rails ERD can also draw single table inheritance, often referred to as specialization. Specialized entities are displayed in grey, because they do not have their own table in the database. An open arrow points to their parent entity. Inheritance is not enabled by default, set inheritance=true to turn it on.
A slight variation on specialization is generalization. This is achieved when an association is re-used on multiple models, forming polymorphic associations. The generalized entities are fictional, because they are not actual models. They also do not correspond to database tables, so they are displayed in grey. Polymorphism is not enabled by default, set polymorphism=true to turn it on.
Alternative notation
Rails ERD's standard notation is designed to be simple. Relationship cardinalities (one-to-many, many-to-many, etc.) are indicated with arrows. But sometimes you also want to know whether a relationship is optional or mandatory. This property of relationships, called participation, can be added to a diagram by using an alternative notation; set with notation=bachman.
The notation that we use was designed by Charles Bachman in 1992. It uses open and closed dots to indicate partial and total participation. Here's an example, a model of fruit orchards...
Notice the use of open and closed dots. An open dot means that the relationship to the other entity is optional, seen from the entity it is next to. A closed dot means that the relationship is mandatory. These properties are automatically determined based on your validators and non-nullable foreign keys. Based on the diagram above we can conclude the following...
|
|
|