2013-06-23 2 views
0

I가 내가 레일 4로 업그레이드 할 때되지 않는 경고 4

class User 
    has_many :relationships 
    has_many :friends, :through => :relationships, -> select: 'friends.*, relationships.weight', order: 'weight DESC' 

, 나는 다음과 같은 경고를 가지고 다음과 같은 관계 :

DEPRECATION WARNING: The following options in your Service.has_many :friends declaration are deprecated: :order,:select. 

나는이 문제를 해결하는 방법? 일반적으로 Rails 4에 대한 진행중인 작업 참조가 있습니까?

답변

2

레일 4에서는 보통 User.where(...) 스타일 쿼리에서 볼 수있는 옵션 중 하나가 람다 형식으로 표시됩니다. 이 :order:select를 포함하는 다음 :through => 부분은 마지막에 머물 필요가 있도록 PROC는 has_many에 두 번째 매개 변수가 될 필요가 않습니다

has_many :friends, -> { select("friends.*, relationships.weight").order("weight desc") }, :through => :relationships 

참고.