考慮下面的代碼片段:阿雷爾AND子句和空狀態
def sql
billing_requests
.project(billing_requests[Arel.star])
.where(
filter_by_day
.and(filter_by_merchant)
.and(filter_by_operator_name)
)
.to_sql
end
def filter_by_day
billing_requests[:created_at].gteq(@start_date).and(
billing_requests[:created_at].lteq(@end_date)
)
end
def filter_by_operator_name
unless @operator_name.blank?
return billing_requests[:operator_name].eq(@operator_name)
end
end
def filter_by_merchant
unless @merchant_id.blank?
return billing_requests[:merchant_id].eq(@merchant_id)
end
end
private
def billing_requests
@table ||= Arel::Table.new(:billing_requests)
end
在方法時,商戶ID變空filter_by_merchant
,應該是什麼,必須返回阿雷爾忽略AND子句效應的價值? 另外,有沒有更好的方法來處理這種情況?
到目前爲止,我所知道的,沒有,你可以傳遞給'和'使得它什麼也不做任何參數。 –
你有沒有試過「return billing_requests.all」? – peter