al3*_*ull 3 ruby datamapper sinatra
我无法确定为什么我在这里收到名称错误.我是DataMapper的新手,但尝试关联.任何帮助表示赞赏.
用户:
class User
include DataMapper::Resource
property :id, Serial, :key => true
property :first_name, String
property :last_name, String
property :company, String
property :city, String
property :country, String
property :mobile_number, Integer
property :email_address, String
property :shahash, String
property :isRegistered, Boolean
belongs_to :event, :required => true
end
DataMapper.auto_upgrade!
Run Code Online (Sandbox Code Playgroud)
事件:
class Event
include DataMapper::Resource
property :id, Serial, :key => true
property :name, String
property :occuring, DateTime
has n, :user
end
DataMapper.auto_upgrade!
Run Code Online (Sandbox Code Playgroud)
小智 6
我认为问题是你DataMapper.auto_upgrade!在每个模型定义之后调用.当您在定义一个模型后调用它时,那里没有子模型.相反,您应该定义和/或要求所有模型,然后执行以下操作:
DataMapper.finalize # set up all relationships properly
# and do a basic model sanity check
DataMapper.auto_upgrade! # create database table if it doesn't exist
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1381 次 |
| 最近记录: |