Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 两个表上具有联接和条件的活动记录查询_Ruby On Rails 3_Activerecord - Fatal编程技术网

Ruby on rails 3 两个表上具有联接和条件的活动记录查询

Ruby on rails 3 两个表上具有联接和条件的活动记录查询,ruby-on-rails-3,activerecord,Ruby On Rails 3,Activerecord,我想使用活动记录执行此查询,以便使查询不会被注入。DB是Postgresql。RubyonRails 3.2.11 def find_possible_duplicates(last_name, date_of_birth, organisation_id) find_by_sql( 'select c.* from clients c' + ' join locations l on c.location_id = l.id' +

我想使用活动记录执行此查询,以便使查询不会被注入。DB是Postgresql。RubyonRails 3.2.11

 def find_possible_duplicates(last_name, date_of_birth, organisation_id)
    find_by_sql( 'select c.* from clients c' +
                 ' join locations l on c.location_id = l.id' +
                 " where c.last_name ILIKE #{last_name}" +
                 " and c.date_of_birth = #{date_of_birth}" +
                 " and l.organisation_id = #{organisation_id}" 
 end        

感谢您的任何帮助

以下是活动记录查询:

 Client.select('clients.*').
 joins('join locations on clients.location_id=locations.id').
 where('last_name like ? and date_of_birth =? and organisation_id = ?',last_name,date_of_birth,organisation_id)