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

Closed
clst opened this Issue Dec 9, 2011 · 3 comments

2 participants

@clst

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 = p.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:

example:

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

That took me ages to figure out.

@vijaydev
Ruby on Rails member

Can you make the relevant changes in docrails?

@clst

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

I have fixed the alias issue.

When will the api be updated?

@vijaydev
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