2014-01-29 3 views
0

대 이전 데이터 내가 필요로하는 어떤 단계에서 이제레일 단일 테이블 상속 내가 레일에 STI 설정이

class Mercedes < Car

class BMW < Car

을 (이름은 무죄를 보호하기 위해 변경되었습니다) 코드에서 Mercedes에 대한 참조를 제거하지만 이전의 이유로 데이터를 그대로두기를 원합니다.

나는 cars 테이블에서 모든 레코드를로드하려고

,이 오류가 발생합니다 :

ActiveRecord::SubclassNotFound: The single-table inheritance mechanism failed 
to locate the subclass: 'Mercedes'. This error is raised because the column 'type' 
is reserved for storing the class in case of inheritance. Please rename this 
column if you didn't intend it to be used for storing the inheritance class 
or overwrite Car.inheritance_column to use another column for that information. 

typeMercedes을 인 cars 테이블의 레코드를 무시하는 방법이 있나요?

+0

실행하려고했던 쿼리는 무엇입니까? – Bijendra

+0

@GhostRider 폭발했을 때 BMW.all을 실행하려고했습니다. 따라서 남은 데이터는 전체 테이블을 쓸모 없게 만듭니다. –

답변

3

Car 클래스에 default_scope { where("cars.type != 'Mercedes'") }을 추가 할 수 있습니다.

그러나 이전 데이터를 프로덕션 데이터베이스에 남겨두면이 같은 임시 해결 방법으로 빌드 할 수 있습니다. 보관해야하는 경우 아카이브를 만든 다음 db에서 제거하거나 데이터를 재구성하여 필요한 코드 변경 사항과 함께 작동하도록하십시오.

+0

@mu : 나는 여전히 Rails 3 땅에 갇혀 있습니다. –

+0

아하이 봐요. 좋은 지적. 귀하의 제안을 반영하도록 질문을 편집했습니다. –

+0

나는 아직도 "do not do it"이 대답의 가장 좋은 부분이라고 생각한다. –