Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
clst opened this Issue · 3 comments

2 participants

clst Vijay Dev
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.

Vijay Dev
Collaborator

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?

Vijay Dev
Collaborator

Thanks. The api will be updated with 3.2 release.

Vijay Dev vijaydev closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.