limiting columns in model association

It's a string, you'd need to do

belongs_to :person, :select => "id AND name"


First, :select defines a string that will go directly in to the SELECT * FROM * WHERE clause of the SQL statements ActiveRecord uses, so "id AND name" will NOT work.

Second, in this particular case you probably shouldn't be limiting the columns on the MODEL level. Instead, defining select for the find will do:

    @posts = Post.find( :all,                         :select => "id, name",                         :conditions => "is_deleted = false",                         :order => "posts.created_at DESC",                         :include => :person)

Ooh.. yeah, it doesn't. :include screws up the select portion of the query. Sorry, I missed that key in the list.

Anyway, is there a reason to limit person to id/name? At this point, you can still do it, but you'll have to use explicit SQL joins.

    @posts = Post.find( :all,                         :select => "posts.*, AS person_id, AS person_name",                         :join => "INNER JOIN #{Person.table_name} ON = posts.person_id",                         :conditions => "is_deleted = false",                         :order => "posts.created_at DESC")

Then your @posts array will have a bunch of Post objects with all their attributes plus two new ones -- person_id and person_name.

Using :include and referencing the Person model off the Post object is much cleaner though...