[Nitro] Re: Og default values

Michael Neumann mneumann at ntecs.de
Fri Feb 25 04:26:08 EST 2005


George Moschovitis wrote:
>>If this is not feasible, then it's better to use NULL as default value
>>for *every* column/type. If you haven't specified a value, and a column
>>is NOT NULL, this will raise an error.
> 
> 
> done,
> 
> added :default option too...

How does this behave?

   class Person
     property :name, String, :default => "noname"
   end

   a = Person.new

   a.name # => "noname"    (1)
   # or
   a.name # => nil         (2)

Assuming case (1):

   a = Person.new
   a.name # => "noname"
   a.name << "-test"
   a.name # => "noname-test"

   b = Person.new
   b.name # => "nonanme-test"  !!!!!!

And for case (2):

   a = Person.new
   a.save
   a.reload
   a.name # => "noname"

   # okay so far, but now the error kicks in

   a.name = nil
   a.save
   a.reload
   a.name # => "noname"   # still noname, even if I assigned nil
                          # (which is a valid value)


Regards,

   Michael



More information about the Nitro-general mailing list