Documentation problem for :finder_sql in ActiveRecord::Associations::ClassMethods #3920

clst opened this Issue Dec 9, 2011 · 3 comments

2 participants


The documentation states this as an example

has_many :subscribers, :class_name => "Person", :finder_sql =>
    'SELECT DISTINCT people.* ' +
    'FROM people p, post_subscriptions ps ' +
    'WHERE ps.post_id = #{id} AND ps.person_id = ' +
    'ORDER BY p.first_name'

multiple problems:

people.* vs. people p alias will not work (on SQLite at least)

String vs. proc

Rails 3.1 requires a proc:


has_many :posts, :finder_sql =>
    proc {"SELECT p.* from posts p join topics t on p.topic_id = where{id}"}

That took me ages to figure out.

Ruby on Rails member

Can you make the relevant changes in docrails?


Apparently this was fixed in commit dbe9a9b rails/docrails@24f0a87#activerecord/lib/active_record/associations.rb
in July but doesn't have it (yet).

I have fixed the alias issue.

When will the api be updated?

Ruby on Rails member

Thanks. The api will be updated with 3.2 release.

@vijaydev vijaydev closed this Dec 15, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment