1

我想做一些类似 SQL的事情AND来为此添加第二个条件:

Article
  .where("date_trunc('day', created_at) = ?", Date.yesterday-(params[:increment].to_i))
  .order('articles.created_at DESC')

第二个条件是如果'site_id' attribute = "HIDE".

提前感谢您的任何提示。

4

2 回答 2

2

只需添加另一个where具有所需条件的子句:

Article
  .where("date_trunc('day', created_at) = ?", Date.yesterday-(params[:increment].to_i))
  .where(site_id: 'HIDE')
  .order('articles.created_at DESC')
于 2017-07-05T17:38:44.873 回答
1

您可以ANDwhere语句中使用:

Article
  .where("date_trunc('day', created_at) = ? AND site_id = 'HIDE'", Date.yesterday-(params[:increment].to_i))
  .order("articles.created_at DESC")
于 2017-07-05T17:41:08.933 回答