7

이 문제에 관해 많은 게시물을 보았지만 문제가 해결되지 않은 것 같습니다.Rails 3.1.3 범위가 지정되지 않은 범위

default_scope where(:is_active => true).order('LOWER(table.name)'); 

내가 다른 (일반) 범위를 가지고 있고, 나는 unscoped를 사용하여 inactive 범위를 만들려면 : 그래서 같은 모델에 default_scope 있습니다. 나는 범위로 정의하고 싶지만, 클래스 메소드로 정의 된 경우에만 작동합니다

# works 
def self.inactive 
    unscoped { where(:is_active => false) } 
end 

# none of these work 
scope :inactive, unscoped { where(:is_active => false) } 
scope :inactive, with_exclusive_scope { where(:is_active => true) } 
scope :inactive, unscoped.where(:is_active => false) 
scope :inactive, lambda { unscoped { where(:is_active => false) } } 
scope :inactive, unscoped { lambda { where(:is_active => false) } } 
unscoped do 
    scope :inactive, where(:is_active => false) 
end 

내가 놓친 방법이 있나요, 아니면이 범위를 정의하는 클래스 메소드를 사용해야합니까?

+0

비슷한 종류의 http://stackoverflow.com/questions/6919307/rails-3-default-scope-scope-with-overrride –

+0

(읽는다면 그곳의 주석은 실제로 해결책이 아니다) –

+0

나는'except'와'only'도 살펴볼 것이다. 그러나'unscoped'와 관련된 문제와 비슷한 또 다른 범위에서'default_scope'을 무효화하는 것처럼 보이지 않는다. 'with_exclusive_scope'. –

답변

6

이 할 수있는 방법이있을 것 같지 않습니다보십시오. github의 레일 레포에 관한 문제를 열었습니다 ...

+2

해결 방법으로 범위가 지정되지 않은 클래스 메서드를 만들면 문제가없는 것으로 간주됩니다. –

+1

참조 용 : https://github.com/rails/rails/issues/4306 –

0

scope :inactive, lambda { unscoped.where(:is_active => false) } 
+0

도 작동하지 않습니다 – sethvargo

+1

하지만 시도 할 수없는 가능성 목록에 추가하십시오 – sethvargo

+0

ftr, 어느 쪽도 아닙니다 unscoped {lambda {...}} – sethvargo

관련 문제