2009-05-17 3 views
3

아래의 클래스가 실패하는 이유는 누구나 자원 할 수 있습니까?후계자 모델 set_schema를 찾을 수 없음

... src/model/user.rb:18: undefined method `set_schema' for User:Class (NoMethodError) 

나는 속편-3.0 lib 디렉토리/폴더에 검토 한 결과와 set_schema 방법은 ClassMethods 모듈에 정의되어 있습니다.

나는 해결책이 간단하다고 확신합니다. 나는 그것이 "있는 그대로"작동해야한다고 생각했습니다 :

require 'sequel' 

class User < Sequel::Model(:user) 

    set_schema do 
    set_primary_key :id 
    String   :name 
    end 
end 
+1

질문을 다시 편집하고 대신 복수 응답을 추가하는이 업데이트를 추가하십시오. –

답변

3

권장되는 방법 ...

LOGGER = Object.new() 
def LOGGER.method_missing(name, args) 
    puts "[#{name}] #{args}" 
end 

Sequel::Model.plugin(:schema)      # I worked this out, but I can't find it documented 

DB = Sequel.sqlite('sql_test.db', :loggers => [LOGGER]) 

unless DB.table_exists?(:user) 
    DB.create_table :user do 
     set_primary_key :id 
     String   :name 
     String   :password 
     String   :eMail 
    end #create_table 
end #table exists 
class User < Sequel::Model(:user) 
3

대답은 스키마 관리를 위해 플러그인을 호출하는 것입니다. 즉.

require 'sequel' 
require 'logger' 

LOGGER = Object.new() 
def LOGGER.method_missing(name, args) 
    puts "[#{name}] #{args}" 
end 

**Sequel::Model.plugin(:schema)**   # I still didn't find this documented 

DB = Sequel.sqlite('sql_test.db', :loggers => [LOGGER]) 


class User < Sequel::Model(:user) 

    set_schema do 
    set_primary_key :id 
    String   :name 
    end 
end 
1

Sequel::Model.plugin(:schema)도 나를 위해 일했습니다. 문서에서 그것을 볼 수 없으며 나는 왜 set_schema을 사용하는 또 다른 작업 프로젝트를 가지고 있기 때문에 왜 그런지 당혹 스럽다.

+0

안녕하세요 Joe ... Y 예, Sequel이 작동하는 방식을 살펴 보았습니다. 스키마와 같은 것에 플러그인을 사용합니다. 속편 메일 링리스트에서 아래에 표시된대로이를 수행하도록 권유했습니다. 행운을 비네. – will