Rails:有条件的 find_by_contents;请语法帮助

发布于 2024-10-15 20:24:55 字数 556 浏览 9 评论 0原文

希望根据 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'"])

有人知道语法应该是什么吗?

Looking to limit a find based on conditions in a Rails 2.0.2.

Find statement:

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

Need to add a condition to limit find

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

Though this doesn't work

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

Anyone know what the syntax should be?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

居里长安 2024-10-22 20:24:55

如果您将条件传递给数组,我认为它需要用于参数化条件。尝试以下任一/两个操作:

    @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'])

If you pass conditions an array, I think it needs to be for a parameterized condition. Try either/both of the following:

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

or

@employees = Employee.find_by_contents(params[:keywords].to_s,                           
                  :include => [ :categories, :revisions, :approvals, 
                                :archives, :related_documents ],
                  :conditions=>["archived = ?",'0'])
因为看清所以看轻 2024-10-22 20:24:55

在向 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}

Was having quite a time with adding a condition to ferret find_by, so I added a post command to filter if it's archived. If you think of a better way still, let me know. Thanks.

@employees = Employee.find_by_contents(params[:keywords].to_s, 
              :include => [ :categories, :revisions, :approvals, 
                            :archives, :related_documents ])
@employees = @employees.find_all {|p| !p.archived}
人海汹涌 2024-10-22 20:24:55

首先,你有什么错误?

并尝试这个

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

Firstly, what error do you have?

And try this

@employees = Employee.find_by_contents(params[:keywords].to_s, :include => [ :categories, :revisions, :approvals, :archives, :related_documents ], :conditions=>["employees.archived = ?", false])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文