ActiveRecordERD
Generate Entity Relationship Diagrams (ERD) for your ActiveRecord models using Mermaid syntax.
Installation
Add this line to your application's Gemfile:
gem 'activerecord-erd'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install activerecord-erd
Usage
This gem adds erd
methods to all your ActiveRecord models:
# Generate an ERD diagram for the User model (class level)
User.erd
# Generate an ERD diagram for a specific user instance
user = User.find(1)
user.erd
# Include empty relationships in the diagram
User.erd(empty: true)
The ERD is generated using Mermaid syntax, which can be rendered in many Markdown viewers including GitHub.
Features
- Visualize model relationships with detailed information
- Show foreign keys and their reference counts
- Distinguish between simple and complex dependencies
- Support for has_many, has_one, belongs_to, and through associations
- Instance-specific diagrams that show only related records
Development
After checking out the repo, run bin/setup
to install dependencies. You can also run bin/console
for an interactive prompt.
To install this gem onto your local machine, run bundle exec rake install
.
Contributing
Bug reports and pull requests are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration.
License
The gem is available as open source under the terms of the MIT License.