
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
-
-
Dan Kubb (dkubb) April 14th, 2008 @ 05:25 PM
- State changed from new to open
-
Sam Smoot April 28th, 2008 @ 12:17 PM
- State changed from open to invalid
Pushing :default off to 1.0. For now if you want a Ruby default, overwrite #initialize.
-
Sam Smoot April 28th, 2008 @ 12:18 PM
Pushing :default off to 1.0. For now if you want a Ruby default, overwrite #initialize.
-
Sam Smoot April 28th, 2008 @ 12:19 PM
Pushing :default off to 1.0. For now if you want a Ruby default, overwrite #initialize.
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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »