views:

74

answers:

3

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 ?

+1  A: 

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.

dkubb
Thanks that helps me to found the error.
Riba
A: 

Try Job.save after your Job.Create :)

Tom
Yes, I don't include the .save or .create ...
Riba
A: 

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.

Riba