0

这是我的代码:

初始化文件:

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'

应用程序文件:

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

请帮忙。

谢谢

4

1 回答 1

2

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

于 2013-03-29T08:40:17.527 回答