任何一个志愿者为什么下面的课程会失败?
... src/model/user.rb:18: undefined method `set_schema' for User:Class (NoMethodError)
我查看了Sequel-3.0 lib /文件夹,并在set_schema
模块中定义了ClassMethods
方法。
我确信解决方案很简单。我认为它应该“按原样”运作:
require 'sequel'
class User < Sequel::Model(:user)
set_schema do
set_primary_key :id
String :name
end
end
答案 0 :(得分:4)
推荐方式......
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)
答案 1 :(得分: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
答案 2 :(得分:1)
Sequel::Model.plugin(:schema)
也为我工作。在文档中看不到它,我为什么感到困惑,因为我有另一个使用set_schema
而没有大惊小怪的工作项目。