getting related object from the active record

Quoting Aljaz Fajmut <rails-mailing-list@andreas-s.net>:

Hello.

How do I access blog object/model from the following active record
class:

class Entry < ActiveRecord::Base

  belongs_to :blog

  def self.test
    puts blog.title
  end
end

In the example above I want to print the blog title.

The class doesn't have a blog, individual entries have blogs.

entry = Entry.find(....whatever, :include => :blog)
puts entry.blog.title

The :include option "eager loads" the blog at the same time as the entry.
Without it, the blog will be loaded when the puts statement executes.

HTH,
  Jeffrey