Rails: Has many through associations — find with AND condition, not OR condition

前端 未结 3 486
盖世英雄少女心
盖世英雄少女心 2021-02-06 19:18

I have the following query method in my ActiveRecord model:

def self.tagged_with( string )
    array = string.split(\',\').map{ |s| s.lstrip }
    select(\'disti         


        
3条回答
  •  悲哀的现实
    2021-02-06 19:54

    You could change your select statement to the following:

    select('distinct photos.*').joins(:tags).where('tags.name = ?',  array.join(' OR '))
    

    Which will properly create the OR string in the where clause.

    ian.

提交回复
热议问题