#1153 ✓duplicate
Gary Yngve

saving in an after :save doesn't save when creating a new obj

Reported by Gary Yngve | December 12th, 2009 @ 08:24 PM

!/usr/bin/env ruby

require 'rubygems'
gem 'dm-core', '~>0.10.2'
require 'dm-core'

DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, 'sqlite3::memory:')

class Foo
include DataMapper::Resource

property :id, Serial property :num, Integer

after :save do

self.num = 42

end end


f = Foo.create(:num=>7)
puts f.num # prints 42
puts Foo.first.num # prints 7, should print 42
f.save # ugh, it wasn't saved after the hook!!!
puts Foo.first.num # prints 42

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket