#188 invalid
Ardekantur

find_or_create does not seem to take default values into account

Reported by Ardekantur | March 23rd, 2008 @ 03:28 PM

require 'rubygems'
require 'data_mapper'

DataMapper::Database.setup( {
  :adapter => 'sqlite3',
  :database => 'blog.db' } )

class Apple < DataMapper::Base
  property :title, :string
  property :weight, :integer, :default => 0
end

DataMapper::Base.auto_migrate!

a = Apple.new :title => "Granny Smith"
a.save

b = Apple.find_or_create :title => "Red Delicious"
b.weight += 1
b.save

An exception will be raised on `b.weight += 1' because the object will look like this after execution of the last line:

#<Apple:0x122f7e4 @new_record=false, @title="Red Delicious", @weight=nil, @id=2>

The @weight parameter is nil, instead of the requested default, 0.

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

Pages