Re: ActiveRecord uses confusing defaults

Rick Olson
Fri, 08 Sep 2006 12:20:41 -0000

On 9/8/06, Jeroen Houben
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:
>
> Hi!
>
> I have an AR model called Submission
> In my submissions table (mysql 5) I have a column called postcode
> (varchar, not null) and a column street (varchar, not null)
>
> s = Submission.new
> s.postcode # => 0
>
> now I would expect this to return nil
>
> s.street # => ''''
> I would expect this to return nil
>
> Is there a reason for this?
>
> Jeroen

It goes by the defaults set in your database.  What''s your schema look
like?

Here''s a snippet from one of my apps:

  create_table "contents", :force => true do |t|
    t.column "article_id",     :integer
    t.column "comments_count", :integer,                 :default
=> 0
  end

>> Content.new.article_id
=> nil
>> Content.new.comments_count
=> 0


--
Rick Olson