#14
Apr 04, 2007

Performing Calculations on Models

Did you know ActiveRecord provides class methods for performing calculations on models? You can even use these methods through associations.
Download (11.7 MB, 2:57)
alternative download for iPod & Apple TV (3.9 MB, 2:57)
Task.sum(:priority)
Task.sum(:priority, :conditions => 'complete=0')
Task.maximum(:priority)
Task.minimum(:priority)
Task.average(:priority)
p = Project.find(:first)
p.tasks.sum(:priority)
p.tasks.sum(:priority, :conditions => 'complete=0')

6 comments

santosh Aug 01, 2007 at 01:59

This is very use ful for new programmers who doing their projects in ROR...
So keep sending comments and what u nw ,u should share with ur thoughts with others and would be better for improving our knowledge....So Keep sending wt u know ..and learn wt u wt u dont no by this format........
And one more thing i want to tel u is please send some material on ROR to my mail.......
OK Thanks,
Santosh


omfg Aug 02, 2007 at 13:33

Hey, you forgot to put your email here so I can send you some info on "ROR".


Joe Grossberg Aug 07, 2007 at 08:40

Next railscast: how to leave comments that don't make you look like a semi-literate teenager.


Matt Grande Apr 14, 2008 at 15:57

What's that funky thing showing your SQL in the background?


roller8 Apr 28, 2008 at 22:26

@Matt: I think you're referring to "tailing the development log". It's a technique for watching what's getting written to the log in real time.


tomlandmeele Jul 23, 2008 at 16:10

me microsoft girl apple german busy english

Add your comment:

(SKIP THIS ONE)

(required)

(not shown)


(required)

subscribe:
sponsored by:
if you want to help:
required:
Get Quicktime Player