开发者

Ruby : Datamapper don't insert in database

I a have the following datamapper ressource :

class Job
  include DataMapper::Resource
  storage_names[:default] = 'job'
  property :id,         Serial
  property :at,         Integer,  :required => true,  :min => 0
  property :name,       Float,    :required => true,  :default => 0
  property :cpu,        Float,    :required => true,  :default => 0
  property :memory,     Float,    :required => true,  :default => 0
end

When do :

DataMapper.auto_migrate!

The table 'job' is correctly created in the database. But when I do :

  Job.create(
    :at      => entry[:timestamp],
    :name    => process.to_s,
    :cpu     => data[0],
    :memory  => data[1]
  )

Nothing is really inserte开发者_JAVA技巧d in the 'job' database table. (Nothing in datamapper log too)

Any idea ?


Try enabling dm-validations and checking #errors in the returned object, this will tell you if there are any problems with the data. If its invalid, DataMapper won't insert anything.


Try Job.save after your Job.Create :)


The error was :

property :name,       Float,    :required => true,  :default => 0

and

:name    => process.to_s,

float <-> String

thats why datamapper don't insert the object database.

Thanks all for your helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜