2011-08-30 5 views
10

을 기본 상위 클래스에서 깰 수액티브 STI : 어떻게 '범위 주어진 레일 3.1 RC6에

class Animal < ActiveRecord::Base 
    default_scope where(legs: 4) 
end 

예상대로 작동하지 않습니다 다음

class Man < Animal 
    default_scope unscoped.where(legs: 2) 
end 

결과 SQL 문을 다음과 같이 보입니다 :

SELECT * FROM animals WHERE legs = 4 AND legs = 2 

부모 클래스의 기본 범위를 완전히 무시하려면 어떻게해야합니까?

default_scope{ unscoped.where legs: 2 } 
default_scope with_exclusive_scope{ legs: 2 } 

답변

8
내가 레일 '소스 코드에 파고 레일 3.1에서 작동하는 솔루션을 함께했다

이 (액티브의 3.1.0.rc6 테스트 :

은 또한 어떤 작품의 다음과, 아무도 시도하지했습니다) :

class Animal < ActiveRecord::Base 
    default_scope where(legs: 4) 
end 

class Man < Animal 
    self.default_scopes = [] 
    default_scope where(legs: 2) 
end 
+0

http://m.onkey.org/default-scopes-and-inheritance-to-the-rescue 도움이 레일즈 3.0에서 작동하는 것 같습니다 : self.default_scoping = [] – jemminger

0

나는이를 찾았다 고하고 나에게

+0

이 링크가 끊어집니다. 어디로 옮겼을 지 아십니까? – BananaNeil