tags:

views:

505

answers:

3

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".

Thanks in advance /will.

require 'sequel'

class User < Sequel::Model(:user)

  set_schema do
    set_primary_key :id
    String          :name
  end 
end
+3  A: 

The answer is to call up the plug-in for schema managing. Viz.

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
will
A: 

Yep Sequel::Model.plugin(:schema) worked for me too. Can't see it in the docs and I'm perplexed as to why, since I have another working project that uses set_schema without fuss.

joecorcoran
Hi Joe ... YYes, I looked over the new way Sequel works now, it uses plugins for things like the schema, etc. On the sequel mailing list they advised me to do it as shown below.Good luck, w.
will
+1  A: 

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)
will