1

希望根据 Rails 2.0.2 中的条件限制查找。

查找语句:

@employees = Employee.find_by_contents(params[:keywords].to_s, :include => [ :categories, :revisions, :approvals, :archives, :related_documents ])

需要添加条件限制查找

:conditions=>["archived = '0'"]

虽然这不起作用

@employees = Employee.find_by_contents(params[:keywords].to_s, :include => [ :categories, :revisions, :approvals, :archives, :related_documents ], :conditions=>["archived = '0'"])

任何人都知道语法应该是什么?

4

3 回答 3

0

首先,你有什么错误?

试试这个

@employees = Employee.find_by_contents(params[:keywords].to_s, :include => [ :categories, :revisions, :approvals, :archives, :related_documents ], :conditions=>["employees.archived = ?", false])
于 2011-02-04T21:55:08.423 回答
0

在向 ferret find_by 添加条件方面花了很多时间,所以我添加了一个 post 命令来过滤它是否已存档。如果您还想到更好的方法,请告诉我。谢谢。

@employees = Employee.find_by_contents(params[:keywords].to_s, 
              :include => [ :categories, :revisions, :approvals, 
                            :archives, :related_documents ])
@employees = @employees.find_all {|p| !p.archived}
于 2011-02-07T18:48:35.260 回答
0

如果您将条件传递给数组,我认为它需要用于参数化条件。尝试以下两种方法之一:

    @employees = Employee.find_by_contents(params[:keywords].to_s, 
                  :include => [ :categories, :revisions, :approvals, 
                                :archives, :related_documents ], 
                  :conditions=> "archived = '0'")

或者

@employees = Employee.find_by_contents(params[:keywords].to_s,                           
                  :include => [ :categories, :revisions, :approvals, 
                                :archives, :related_documents ],
                  :conditions=>["archived = ?",'0'])
于 2011-02-04T21:17:16.420 回答