Riba
Riba

Reputation: 1118

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 inserted in the 'job' database table. (Nothing in datamapper log too)

Any idea ?

Upvotes: 0

Views: 521

Answers (3)

Riba
Riba

Reputation: 1118

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.

Upvotes: 0

Tom
Tom

Reputation: 34366

Try Job.save after your Job.Create :)

Upvotes: 0

dkubb
dkubb

Reputation: 2126

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.

Upvotes: 1

Related Questions