开发者

Problem with DataMapper, Integer property

开发者 https://www.devze.com 2023-02-21 22:51 出处:网络
I have the following class in my sinatra app (app.rb) class Project include DataMapper::Resource property :id, Serial

I have the following class in my sinatra app (app.rb)

class Project
  include DataMapper::Resource
  property :id, Serial
  property 开发者_运维知识库:creatorid, Integer, :key => false
  property :name, String
end


Project.auto_migrate! unless Project.storage_exists?

and in the post method, I have:

project = Project.create
project.creatorid = GetLoggedInUserId() #returns an int
project.name = params['projectname']

But when I'm getting the following error: no such column: creatorid (on the project.creatorid... line)

Suggestions?


You coult try with new method instead that create since latter one is used to generate and save an item on the go while the former one is used to generate an empty item that can be then filled (like you do) and then saved with project.save().

Take a look at documentation here..

0

精彩评论

暂无评论...
验证码 换一张
取 消