Nested has_many :through problem with Rails 3


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

  # Attempt at an updated version for Rails 3. This fails.
  def dates_with_photos

# Example:

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

Any ideas?



I am experiencing the same problem as daniel

- has_many through association

- get invalid sql when try to use a scope with "select distinct":
basically, the "select" i specify does not override the default implicit
select of the has_many join, but instead gets appended to it (as in
daniel's example)

Does anyone know if this is by design, or a bug?


I'm guessing bug. As of Arel 2.0.6 I'm no longer getting invalid sql,
but I'm not getting valid results either.


Disregard, it's still generating invalid sql.