2016-08-01 66 views
0

我Mongoid來源看見沒有PROC可以被髮送到聯想法,什麼是實現低於AR協會與Mongoid最佳實踐:協會PROC爲mongoid

class Task 
    ... 

    belongs_to :creator, ->{where(type: :manager)}, class_name: "User" 
    belongs_to :acceptor, ->{where(type: :acceptor)}, class_name: "User" 
end 

回答

0

看來我找到答案。 Mongoid中的關係方法接受塊作爲第三個參數。

belongs_to :creator, class_name: "User", inverse_of: :created_tasks do 
    ->{ where(type: :manager)} 
    end 

belongs_to :executor, class_name: "User", inverse_of: :accepted_tasks do 
    ->{where(type: :acceptor)} 
end