Re: [DataMapper] Decimal datatype

25 views
Skip to first unread message

Antonio Antillon

unread,
May 23, 2013, 7:58:55 PM5/23/13
to datam...@googlegroups.com

You are asigning foo to the name field... and nothing to the data field... in your model, you declared data as a requires field... if you don't assign anything to it, it's nil... and data must have a value... that's why.

On May 23, 2013 11:18 AM, "Nicholas Wieland" <nicholas...@gmail.com> wrote:
Hi *, I have a model like this: 

  class Trait
    include DataMapper::Resource

    property :id, Serial
    property :name, Slug, :required => true
    property :data, Decimal, :required => true

    has n, :items, :through => :assignments
    has n, :assignments
  end

and if I do:

irb(main):029:0> t = Trait.new
=> #<Trait @id=nil @name=nil @data=nil>
irb(main):030:0> t.data = 1.0
=> 1.0
irb(main):031:0> t
=> #<Trait @id=nil @name=nil @data=nil>
irb(main):032:0> t.name = "FOO"
=> "FOO"
irb(main):033:0> t
=> #<Trait @id=nil @name="foo" @data=nil>
irb(main):034:0> t.save
=> false
irb(main):035:0> t.errors.inspect
=> "#<DataMapper::Validations::ValidationErrors:0x00000005bb5e40 @resource=#<Trait @id=nil @name=\"foo\" @data=nil>, @errors={:data=>[\"Data must not be blank\"]}>"

can someone explain me why I'm not able to set the data attribute?

TIA,
  ngw

--
You received this message because you are subscribed to the Google Groups "DataMapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to datamapper+...@googlegroups.com.
To post to this group, send email to datam...@googlegroups.com.
Visit this group at http://groups.google.com/group/datamapper?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Clifford Heath

unread,
May 24, 2013, 3:31:37 AM5/24/13
to datam...@googlegroups.com

I see him setting data to 10 - did you miss that? I'm not where I can try this, but I'd rename data and see if that helps. DM has internal methods, perhaps you have a a collision?

Reply all
Reply to author
Forward
0 new messages