Skip to content

Instantly share code, notes, and snippets.

@bsodmike

bsodmike/erd.png Secret

Created July 4, 2011 15:05
Show Gist options
  • Save bsodmike/9a908e8f7d90cfa46168 to your computer and use it in GitHub Desktop.
Save bsodmike/9a908e8f7d90cfa46168 to your computer and use it in GitHub Desktop.
Rails-erd yuml_erd rake task error.
require "rails_erd/diagram"
class YumlDiagram < RailsERD::Diagram
setup { @edges = [] }
# Invoked once for each relationship
each_relationship do |relationship|
line = if relationship.indirect? then "-.-" else "-" end
arrow = case
when relationship.one_to_one? then "1#{line}1>"
when relationship.one_to_many? then "1#{line}*>"
when relationship.many_to_many? then "*#{line}*>"
end
@edges << "[#{relationship.source}] #{arrow} [#{relationship.destination}]"
end
# Should save or return the generated diagram
save { @edges * "\n" }
end
task :yuml_erd do
# Load all application models.
Rails.application.eager_load!
# Output diagram to $stdout.
puts YumlDiagram.create
end
class User < ActiveRecord::Base
has_many :bookings
class Booking < ActiveRecord::Base
belongs_to :machine
belongs_to :user
class Machine < ActiveRecord::Base
has_many :bookings
## This fails (eager_loading disabled here):
$ rake yuml_erd --trace
** Invoke yuml_erd (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute yuml_erd
Warning: Ignoring invalid association :bookings on User (model Booking exists, but is not included in domain)
## This works:
$ rake erd title='Booking System' attributes=foreign_keys,content
Loading application environment...
Loading code in search of Active Record models...
Generating Entity-Relationship Diagram for 3 models...
Done! Saved diagram to ERD.pdf.
## With eager_loading:
** Invoke yuml_erd (first_time)
** Execute yuml_erd
rake aborted!
No such file to load -- devise/confirmations_controller
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment