Rozważmy następujący fragment kodu:Arel i klauzula i pusty stan
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
W metodzie filter_by_merchant
gdy id kupiec staje się pusta, jaka powinna być wartość, która musi zostać zwrócony do AREL zignorować i skutku klauzuli? Czy istnieje lepszy sposób na obsługę tego przypadku?
O ile mogę powiedzieć, że nie ma żadnych argumentów, które można przekazać do 'and' które sprawiają, że nic nie robią. –
Czy próbowałeś "return billing_requests.all"? – peter