Quoting Aljaz Fajmut <[email protected]>:
> 
> 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

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to