[6] pry(main)> c Account
Columns for 'accounts'
id :integer
created_at :datetime
updated_at :datetime
address :string
city :string
state :string
zip :string
phone_number :string
last_ip :string
# Print formatted column names and type info for ActiveRecord models
def fields(model)
puts "Columns for '#{model.table_name}'"
width = model.columns.inject(0) { |max_width, col| col.name.size > max_width ? col.name.size : max_width }
_columns = model.columns.collect do |c|
" %-#{width + 2}s :%s" % [c.name, c.type]
end.join("\n")
puts _columns
end
alias :c :fieldshttp://www.pgmodeler.com.br/ https://github.com/pgmodeler/pgmodeler
I had spent a week slowly isolating this brutal memory leak until being able to see the whole ObjectSpace illuminated my problem.
Here's the thing: I already know how many models I have (I just look in app/models) and which columns back them (I just look in db/schema).
The thing I often want that 1) ActiveRecord doesn't give me and 2) I haven't seen in any tool yet is a diagram of the relationships. So I have two models, A and B, and A has many B. How do you diagram that? Typically I've seen arrows: B points to A, with the words "has many" written next to it. The thing is, if I have 30 models in my app, I'm not going to be able to read this at a glance. Words are too small. Diagrams are meant to be rough pictures.
The way I visualize this in my head and consequently diagram this on a whiteboard is, multiple instances of B point back to A. It's easy. If you have a has_one instead, then only one B points back to A. Makes sense right? No one does this. I often wonder why.