Live data from Hacker News

Visualizing Rails Schemas with the RailRoady Gem

engineering.coachup.com

11–14 of 14 posts

Re: Visualizing Rails Schemas with the RailRoady Gem

#11

Earlier quoted context omitted.

Instead of annotate models, I have a function in my .irbrc/.pryrc that will print out the columns for me when I'm in a rails console (I usually have one open almost all of the time). I prefer this to cluttering my model files. [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…

Do you keep the rails console running constantly? It seems more inconvenient to start and stop the rails console than navigate files for your schema, which is also searchable by virtue of it being written down.

Not really, it's just usually when I'm trying out different queries in the console that I have the, "oh crap, what did I name that column" moments. If I need to search for something in particular, I just search schema.rb.

Re: Visualizing Rails Schemas with the RailRoady Gem

#14
The problem I have with these tools is that the diagram it produces is really not that great. I guess it tells you what models you have, the columns they have, and whether a model is tied to another one... but not much else.

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.

Post reply on HN