如何摆脱续集中的续集错误?

时间:2013-03-28 19:49:10

标签: ruby rubygems sequel

这是我的代码:

init文件:

require 'sequel'
DB = Sequel.connect('sqlite://data.db')

DB.drop_table?(:restaurants)
DB.create_table :restaurants do
primary_key :id
String :name
end

DB.drop_table?(:category)
DB.create_table :category do
primary_key :id
String :name
end


DB.drop_table?(:items)
DB.create_table :items do
primary_key :id
foreign_key :restaurant_id
foreign_key :category_name
String :name
Float :price
end

require_relative './restaurant'
require_relative './categories'
require_relative './item'

app文件:

require_relative './models/init

p = Category.create(:name => 'Pizza')
c = Category.create(:name => 'Calazone')
pa = Category.create(:name => 'Pasta')
s = Category.create(:name => 'Salad')
d = Category.create(:name => 'Dessert')
dr = Category.create(:name => 'Drink')
si = Category.create(:name => 'Side')`

但是我收到了这个错误:

/home/ben/.rvm/gems/ruby-1.9.3-p385/gems/sequel-3.45.0/lib/sequel/model/base.rb:1780:in `block in set_restricted': method name= doesn't exist (Sequel::Error)
    from /home/ben/.rvm/gems/ruby-1.9.3-p385/gems/sequel-3.45.0/lib/sequel/model/base.rb:1767:in `each'
    from /home/ben/.rvm/gems/ruby-1.9.3-p385/gems/sequel-3.45.0/lib/sequel/model/base.rb:1767:in `set_restricted'
    from /home/ben/.rvm/gems/ruby-1.9.3-p385/gems/sequel-3.45.0/lib/sequel/model/base.rb:1278:in `set'
    from /home/ben/.rvm/gems/ruby-1.9.3-p385/gems/sequel-3.45.0/lib/sequel/model/base.rb:1736:in `initialize_set'
    from /home/ben/.rvm/gems/ruby-1.9.3-p385/gems/sequel-3.45.0/lib/sequel/model/base.rb:920:in `initialize'
    from /home/ben/.rvm/gems/ruby-1.9.3-p385/gems/sequel-3.45.0/lib/sequel/model/base.rb:156:in `new'
    from /home/ben/.rvm/gems/ruby-1.9.3-p385/gems/sequel-3.45.0/lib/sequel/model/base.rb:156:in `create'
    from app.rb:4:in `<main>'"

请帮助。

由于

1 个答案:

答案 0 :(得分:2)

你没有发布你的类别模型,但我猜它实际上并没有查看类别表(可能是类别表)。您要么将数据库表重命名为类别,要么告诉您的类别模型使用类别表。如果不是这样,您可能想发布您的型号代码。