這裏是我的模型:迭代一個named_scope內的has_many收集
class Message < ActiveRecord::Base
has_many :comments
attr_accessible :read #bool
def unread_comments?
comments.each { |comment| return true unless comment.read?}
false
end
end
class Comment < ActiveRecord::Base
belongs_to :message
attr_accessible :read #bool
end
這是我所期待的事:我想在信息創建一個named_scope,叫unread
基本上返回如果屬實任何消息的評論未讀或消息本身未讀。有什麼辦法可以做到這一點?