0
我有以下在“书”型号命名范围使用金额和IFNULL条件内命名范围
named_scope :batch_book_status_55, lambda { |batch_id| {
:select => "ifnull(sum(if(BK_DB_STATUS_FK = 55, 1, 0)), 0) as ASSIGNED",
:conditions => ["BK_BATCH = ?", batch_id]
}}
<% Book.batch_book_status_55(batch.BATCH_ID).each_with_index do |book, index| %>
<% if book.ASSIGNED.to_i != 0%>
Assigned : <%= book.ASSIGNED %>
<% end %>
<% end %
下面显示的代码的书在特定批次与状态的数量= 55(BK_DB_STATUS_FK = 55 )。
我有点困惑与命名范围代码。如果有人能向我解释代码,我将不胜感激。
感谢提示:) – Kim 2013-05-08 14:41:47
接受答案,如果你认为它有帮助:) – pungoyal 2013-05-08 17:43:31