Hi,

Rails 3.0.3
Ruby 1.8.7

We've got a nested method we're trying to update for Rails 3. However,
it appears to be generating invalid sql. The old Rails 2 method
worked. What am I doing wrong?

# The tables in question are sites, photos, site_photos

# In the Site model
has_many :photos, :through => :site_photos do
  # Old method. This works.
  #def dates_with_photos
  #  find :all, :select => 'distinct date_taken', :order =>
'date_taken'
  #end

  # Attempt at an updated version for Rails 3. This fails.
  def dates_with_photos
    order("date_taken").select("distinct(date_taken)").all
  end
end

# Example:
Site.find(5).photos.dates_with_photos

# It generates invalid sql. This is the bit that's invalid:
SELECT "photos".*, distinct(date_taken) FROM "photos";

Any ideas?

Regards,

Dan

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

Reply via email to