Mark James wrote:
> This may work:
>
> class Folder < ActiveRecord::Base
> has_one :most_recent_note, :class_name => 'Note',
> :foreign_key => :note_id, :conditions =>
> 'notes.created_at = (select max(created_at) from notes)'
> end
>
> folders = Person.find(1, :include => {:folders => :most_recent_note})
Sorry, didn't think that one through properly. How about:
has_one :most_recent_note, :class_name => 'Note', :conditions => <<END
notes.id = (select max(id) from notes where notes.folder_id = folders.id)
END
--
Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.com
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---