2011-08-26 5 views
3

나는 데이터베이스 이름을 수동으로 설정해야하는 간단한 모델이 있습니다.레일스 : oracle set_sequence_name 무시됩니다

또한 오라클 데이터베이스를 사용하고 있으므로 자동 증가 ID를 가질 수 있도록 시퀀스 이름을 설정합니다.

레일 콘솔을 실행하고 모델을 만들려고하면 다시 돌아와 시퀀스를 찾을 수 없다고 말합니다. 이상한 부분은 set_sequence_name에서 설정 한 시퀀스가 ​​아니라는 것을 발견 할 수없는 시퀀스입니다.

모델이는 내 설정 순서 이름 라인을 무시과 같은

class Survey < ActiveRecord::Base 
    set_sequence_name "SURVEY.SQ_SURVEY_ID" 
    set_table_name "SURVEY.SURVEYS" 
end 

콘솔 오류

ActiveRecord::StatementInvalid: ActiveRecord::JDBCError: ORA-02289: 
sequence does not exist: select SURVEY.SURVEYS_seq.nextval id from dual 

.

방금 ​​누락 되었습니까?

+0

음 ..... activekeord-jdbc의 버그 일 수 있습니다. http://kenai.com/jira/browse/ACTIVERECORD_JDBC-133 – joekarl

답변

2

명확히, 이것은 지금까지 내가 말할 수있는

10g의 오라클 작동이는 JDBC 어댑터의 버그 (여기 http://kenai.com/jira/browse/ACTIVERECORD_JDBC-133 참조). 주변의 일을 위해 내가 수동으로이 같은 전에 생성 필터 ID를 설정 해요 :

class Survey < ActiveRecord::Base 
    set_table_name "SURVEY.SURVEYS" 

    before_create do 
    #since we can't use the normal set sequence name we have to set the primary key manually 
    #so the execute command return an array of hashes, 
    #so we grab the first one and get the nextval column from it and set it on id 
    self.id = ActiveRecord::Base.connection.execute("select SURVEY.SQ_SURVEY_ID.nextval id from dual")[0]["id"] 
    end 

end 
+0

제게는 Ruby 친숙한 객체를 얻기 위해'execute'에서'exec_query'로 변경해야했습니다. – shakerlxxv

3

FWIW : 을 내가 멀리에있어 11g 사용 :

self.id = ActiveRecord::Base.connection.execute("select SURVEY.SQ_SURVEY_ID.nextval id from dual").fetch 

그것은 내 경우 것으로 나타납니다, 시퀀스는 가져 오기를 수행해야하는 커서를 반환합니다.

11g/rails 3.1