0
votes

Have a Datamapper class defined like this:

require 'rubygems'
require 'data_mapper'
require 'dm-core'

DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/db/eventdb.sqlite")

class Temp 
  include DataMapper::Resource
  Event.raise_on_save_failure = true

  property :id, Serial
  property :temp1, String, :length => 50
  property :temp2, String
  property :temp3, String
  property :created_at, Time
  property :updated_at, Time

  attr_accessor :temp1, :temp2, :temp3

  class << self

  end

end

Which creates a table in SQLite with this syntax:

~ (0.024280) CREATE TABLE "temps" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "temp1" VARCHAR(50), "temp2" VARCHAR(50), "temp3" VARCHAR(50), "created_at" TIMESTAMP, "updated_at" TIMESTAMP)

Yet when I run this code it produces an insert statement with empty values other then the timestamp entries:

irb(main):001:0> @t = Temp.new
=> #<Temp @id=nil @temp1=nil @temp2=nil @temp3=nil @created_at=nil @updated_at=nil>
irb(main):002:0> @t.temp1 = "Test1"
=> "Test1"
irb(main):003:0> @t.dirty?
=> true
irb(main):004:0> @t.save
 ~ (0.002224) INSERT INTO "temps" ("created_at", "updated_at") VALUES ('2014-05 12T19:26:15.640051-04:00', '2014-05-12T19:26:15.639557-04:00')
=> true

Any thoughts as to why my properties, in this case temp1 is not saving to the database? Thanks in advance.

1

1 Answers

0
votes

Remove this line: attr_accessor :temp1, :temp2, :temp3

It probably redefines Datamapper's setters.