我在“书”模型中有以下命名范围
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) 的书籍数量。
我对命名范围代码有点困惑。如果有人可以向我解释代码,我将不胜感激。