View Single Post
  #2 (permalink)  
Old October 8th, 2009, 06:45 PM
Antonio Cangiano Antonio Cangiano is offline
Registered User
 
Join Date: Apr 2009
Location: Toronto, Canada
Posts: 9
Thanks: 0
Thanked 1 Time in 1 Post
Smile

Hi Dave,

in that section I employed two different ways of specifying conditions. The simplest one is to use a hash:

Code:
Article.find(:all, :conditions => { :published => true }, :order => "published_at DESC")
This can also be expressed as an array whose first element is a string containing the parameterized condition. For example, the line above could be rewritten as follows:

Code:
Article.find(:all, :conditions => ["published = ?", true], :order => "published_at DESC")
Using an array is more flexible than a hash, because you can specify the condition however you wish. The hash only allows you to specify an exact value to match one or more columns.

In fact, later in the same section of the book I used:

Code:
Article.find(:all, :conditions => [“published = ? AND published_at <= ?”, true, Time.now.utc], :order => “published_at DESC”)
Notice how published_at is compared with <=. You couldn't express this with the hash syntax.

I hope this helps clarify the issue for you. If it doesn't, please don't hesitate to ask further questions.

Cheers,
Antonio