You should take advantage of the association proxies. Something like
this should work.
class Magazine
has_many :subscriptions
has_many :subscribers, :through => :subscriptions
end
class Subscription
belongs_to :magazine
belongs_to :subscriber
end
class Subscriber
has_many :subscriptions
end
Now you can do calculations like this:
class Magazine
def youngest_subscriber_birthday
subscribers.calculate(:max, :date_of_birth)
end
end
You should be able to do the calculation the same way for your
'enrich_bead_count_hemo'.
-Dan Manges
http://www.dcmanges.com/blog
On Sep 20, 10:06 pm, dschruth <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm trying to sum up the records in a related table that used to just
> be a child table. This line used to work:
>
> table1.sum(:enrich_bead_count_hemo, :conditions => "table2_id = " +
> id.to_s)
>
> now I've got an intermediate "has and belongs to many" = HABTM table
> inbetween them. Could somebody help me figure out how to sum across
> two tables? I'm thinking i might have to use the custom SQL "join"
> attribute of the sum method.
>
> Thanks,
>
> Dave
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---