2013-05-08 74 views
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 )。

我有點困惑與命名範圍代碼。如果有人能向我解釋代碼,我將不勝感激。

回答