Rails -: joins disinfection / replacement

Is it possible to specify parameters for: union in the same way: conditions?

here is an example (sql code doesn't matter)

named_scope :threads, { :joins => [" LEFT JOIN groups_messages gm ON messages.id=gm.message_id AND gm.group_id IN (?) ",@group_ids_array], :conditions => ["creator_id=? AND messages.id IN (?)", current_user_id, @message_ids_array] } 

in this example, the parameters for: conditions will be inserted correctly, but for: joins I will get an error

  Association named ' LEFT JOIN groups_messages gm ON messages.id=gm.message_id and gm.group_id IN (?) ' was not found; perhaps you misspelled it? 

Which function replaces the parameters for: conditions?

+6
join ruby-on-rails substitution
source share
1 answer

You can use the ActiveRecord :: sanitize_sql_array method.

 ActiveRecord::sanitize_sql_array ['gm.group_id IN (?)', @group_ids_array] 
+7
source share

All Articles