DataMapper 保存失败但没有错误
当我尝试使用 DataMapper 修改并保存模型时,出现 SaveFailure 异常,但没有错误。
具体来说,我看到这条消息: “MonthlyBill#save 返回 false,MonthlyBill 未保存”
这是执行保存的代码:
post '/monthly_bills' do
with_authenticated_user do |user|
description = params[:description]
expected_amount = params[:expected_amount]
pay_period = params[:pay_period]
monthly_bill = MonthlyBill.new(:description=>description, :expected_amount=>expected_amount, :pay_period=>pay_period)
user.monthly_bills << monthly_bill
user.save
end
用户模型:
class User
include DataMapper::Resource
property :id, Serial
property :email_address, String
property :password, String
has n, :monthly_bills
has 1, :current_pay_period
end
MonthlyBill 模型:
class MonthlyBill
include DataMapper::Resource
property :id, Serial
property :description, String
property :expected_amount,Decimal
property :pay_period, Integer
belongs_to :user
end
问题是什么,更重要的是,如何让 DataMapper 更具体地告诉我出了什么问题?
When I try to modify and then save a model using DataMapper I get a SaveFailure exception but no errors.
Specifically I see this message:
"MonthlyBill#save returned false, MonthlyBill was not saved"
This is the code doing the saving:
post '/monthly_bills' do
with_authenticated_user do |user|
description = params[:description]
expected_amount = params[:expected_amount]
pay_period = params[:pay_period]
monthly_bill = MonthlyBill.new(:description=>description, :expected_amount=>expected_amount, :pay_period=>pay_period)
user.monthly_bills << monthly_bill
user.save
end
The User model:
class User
include DataMapper::Resource
property :id, Serial
property :email_address, String
property :password, String
has n, :monthly_bills
has 1, :current_pay_period
end
The MonthlyBill model:
class MonthlyBill
include DataMapper::Resource
property :id, Serial
property :description, String
property :expected_amount,Decimal
property :pay_period, Integer
belongs_to :user
end
What is the issue and, more importantly, how can I get DataMapper to tell me more specifically what is wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯 - 那些资本化的财产对我来说看起来令人担忧。我会做...
然后尝试:
Hmm - those capitalised properties look worrying to me. I would do...
And then try: