如何解决找不到child_modelNameError
| 我无法确定为什么在这里出现名称错误。我是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!
事件:
class Event
include DataMapper::Resource
property :id,:key => true
property :name,String
property :occuring,DateTime
has n,:user
end
DataMapper.auto_upgrade!
解决方法
我认为问题在于您在每个模型定义后都叫
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
, 在模型目录中添加一个初始化文件,然后将所有DataMapper.finalize语句移至该文件(即,从各个模型文件中删除finalize语句)
app / models / init.rb
require_relative \'file_name\'
require_relative \'another_model_file_name\'
DataMapper.finalize
然后在您的应用程序文件中需要init文件
require_relative \'models/init\'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。