I have an inner join query that Action Record can''t seem to pull off 
conventionally, so I''m trying to use :finder_sql to utilize an sql
query
that works beautifully in SQL. The problem is, when I try to call the 
method, I get the following:
private method `gsub'' called for #<Array:0x267de04>
Here is my has_many code:
has_many :mod_privileges,
         :finder_sql => [''SELECT assignments.* FROM assignments
INNER
JOIN permissions ON assignments.publisher_id = permissions.publisher_id 
WHERE permissions.user_id = #{current_user.id} AND (permissions.role_id 
= 3 OR (permissions.role_id = 4 and permissions.assignment_id = 
assignments.id))'']
and a simple test bit I threw into the view:
<%= debug(current_user.mod_privileges)  %>
I was using has_many :through, but there seemed to be no way to do an 
inner join on something other than the column referencing the main 
select table.
Suggestions?
-- 
Posted via http://www.ruby-forum.com/.
Nevermind. I forgot the :class_name. This works:
  has_many :mod_privileges,
           :class_name => "Assignment",
           :finder_sql => "SELECT assignments.* FROM assignments INNER 
JOIN permissions ON assignments.publisher_id = permissions.publisher_id 
WHERE permissions.user_id = #{current_user.id} AND (permissions.role_id 
= 3 OR (permissions.role_id = 4 and permissions.assignment_id = 
assignments.id))"
However, now I''m getting:
uninitialized constant User
I''m using Acts_as_Authenticated which gives me access to the user via 
current_user, but I''m assuming since this has_many method is IN the
User
model it''s not working?
-- 
Posted via http://www.ruby-forum.com/.
Apparently Analagous Threads
- Help on drying code
- [AR] #{id} namespace visibility used in finder_sql
- Change the value stored in inheritance_column
- It this possible: finder_sql-like behavior for belongs_to?
- How do I combine :finder_sql and :conditions to perform a sub-search on a custom has_many relationship?