Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequel Model set_schema not found

Tags:

ruby

sequel

Can any one volunteer why the class below fails?

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

I've looked in the Sequel-3.0 lib/ folder and the set_schema method is defined in a ClassMethods module.

I'm sure the solution is simple. I was thinking it should work "as is":

require 'sequel'

class User < Sequel::Model(:user)

  set_schema do
    set_primary_key :id
    String          :name
  end 
end 
like image 492
will Avatar asked Feb 28 '23 17:02

will


1 Answers

Recommended way ...

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)
like image 175
will Avatar answered Mar 08 '23 23:03

will