#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')

RSS Feed for Episode Comments 8 comments

1. 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


2. omfg Aug 02, 2007 at 13:33

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


3. 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.


4. Matt Grande Apr 14, 2008 at 15:57

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


5. 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.


6. tomlandmeele Jul 23, 2008 at 16:10

me microsoft girl apple german busy english


7. lajunta Oct 18, 2008 at 22:04

Very good tutorial..Thank you, Ryan.


8. Tiffany replica Cuff Links May 07, 2009 at 00:29

Very good tutorial..Thank you

Add your comment:

(SKIP THIS ONE)

(required)

(not shown)


(use pastie or gist for code)

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