3

Ruby on Rails 3.2.2 と Squeel gem を使用しています。OR複数のスコープ メソッドを使用して、それらのスコープ メソッドの SQL 条件に関連する句を含むSQL クエリを生成する方法があるかどうかを知りたいです。つまり、私は持っています:

class Article < ActiveRecord::Base
  def self.scope_method_1
    ... # scope_method_1 SQL conditions
  end

  def self.scope_method_2
    ... # scope_method_2 SQL conditions
  end

  def self.scope_method_combination
    # I am looking for something like
    #
    # where{scope_method_1 | scope_method_2} # Note: The '|' means the SQL 'OR' clause in the Squeel context
    #
    # so to generate the following SQL query:
    #
    # SELECT FROM articles WHERE <scope_method_1 SQL conditions> OR <scope_method_2 SQL conditions>
  end
end

スコープ メソッドを使用してSQLOR句を生成することは可能ですか (Squeel gem を使用するかどうかによって)?

4

1 に答える 1

1

これについてはsqueel issue trackerで議論してきましたが、基本的な答えはノーのようです。少なくともスコープではありません。しかし、スコープをシフターに変換すれば可能です。

于 2012-07-12T02:56:08.497 に答える