---
title: Command-Line Utility to Interrogate Models
teaser: Here's a little script to better understand your ActiveRecord models.
tags: web,rails
author: Tammer Saleh
published_on: 2006-10-19
---

If you run the `show_model` script with no arguments, it prints a little tree
showing the object hierarchy:

<pre>
<samp>ActionMailer::Base
    Notifier
ActiveRecord::Base
    Tag
    Posting
        Comment
        Entry
    Preferences
    User
    Group</samp>
</pre>

Note that, in this example, comments and entries are subclasses of `Posting`
(using single table inheritance).

More useful, though, is getting a quick reference on what class methods,
instance methods, associations, and table columns a model has:

<pre>
<samp>User < ActiveRecord::Base
  Class Methods:
    login
  Instance Methods:
    has_access_to?
    password_confirmation
    password_confirmation=
    posts_about
    tags
  Associations:
    has_many   Comments
    has_many   Entries
    has_many   Groups
    has_many   Postings
    has_many   Postings as non_comment_postings
    has_one    Preferences as preferences
  DB Columns:
    active     (boolean)
    admin      (boolean)
    birth_date (date)
    created_on (datetime)
    email      (string)
    first_name (string)
    id         (integer)
    last_login (datetime)
    last_name  (string)
    password   (string)
    prev_login (datetime)
    updated_on (datetime)</samp>
</pre>

Anyways, I thought I'd post this in case it helps anyone else. Should also say
that it currently assumes that you're in the base `RAILS_DIR` directory.

Next up is a [rails2dot] that doesn't suck.

[rails2dot]: http://www.graphviz.org/
