Forum: Ruby on Rails A "ruby way" to build a sql-aggregate accessor ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
peter.fitzgibbons (Guest)
on 2005-11-22 00:11
(Received via mailing list)
HI all,

I have an AR doing the following :

class Home < ActiveRecord::Base

has_many :home_milestone

def home_milestone_last_update
hm = Home::find_by_sql ["SELECT MAX(updated_on) as last_update FROM
home_milestones WHERE home_id = ?", id]
return hm[0].last_update unless hm.size == 0
end #def home_milestone_last_update

end

This give me usage :
irb> h.home_milestone_last_update
=> "2005/11/21 16:02:46"

What i'd like to have is this usage (notice the '.' instead of '_' :

irb> h.home_milestone.last_update
=> "2005/11/21 16:02:46"

Does my request place the functionality under the HomeMilestone class
then?
What does that look like? Am I walking downt the path to insanity?

Thanks all.
dom (Guest)
on 2005-11-22 02:00
(Received via mailing list)
On Monday 21 November 2005 22:08, Peter F. wrote:
> home_milestones WHERE home_id = ?", id]
>
> irb> h.home_milestone.last_update
> => "2005/11/21 16:02:46"
>
> Does my request place the functionality under the HomeMilestone class
> then? What does that look like? Am I walking downt the path to
> insanity?

Make a Milestone class?
This topic is locked and can not be replied to.