# Rails overriding database default value?

**URL:** <https://www.ruby-forum.com/t/rails-overriding-database-default-value/147798>\
**Category:** Rails\
**Created:** [September 5, 2008, 3:39pm UTC](https://www.ruby-forum.com/t/rails-overriding-database-default-value/147798 "2008-09-05T15:39:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4da419/32.png) [@pepe](https://www.ruby-forum.com/u/pepe)\
**Post date:** [September 5, 2008, 3:39pm UTC](https://www.ruby-forum.com/t/rails-overriding-database-default-value/147798/1 "2008-09-05T15:39:49Z")

</div>

Hello.

This is a new post for a message I didn’t get any answers to. I hope  
this post catches somebody’s eye and helps me with the issue. Sorry  
for the duplication but this is driving me nuts.

The environment is:

- Ruby version is 1.8.6
- Rails version is 1.2.3.
- Database is Oracle (10g) in which I have a table with one defined  
as:  
MY\_FIELD NUMBER(1,0) DEFAULT ‘2’

When a record is created in the database the value that invariable  
gets posted to the table is 0 (zero) instead of 2. However, if I  
change the field to:  
MY\_FIELD NUMBER(2,0) DEFAULT ‘2’, the default value of 2 is  
correctly posted.

Is there a reason Rails would override the value for a NUMBER(1,0)  
field? Is it believing that the field is a true/false container and  
changes the default to a 0 (zero) since it is not a 1 (‘true’)?

Any ideas why this is happening and/or how to solve it short of  
modifying the column’s length?

Thanks in advance.

Pepe

---

<div class="post-metadata">

**Author:** ![pepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4da419/32.png) [@pepe](https://www.ruby-forum.com/u/pepe)\
**Post date:** [September 5, 2008, 3:43pm UTC](https://www.ruby-forum.com/t/rails-overriding-database-default-value/147798/2 "2008-09-05T15:43:20Z")

</div>

On 5 Sep 2008, at 14:39, pepe wrote:

> - Database is Oracle (10g) in which I have a table with one defined  
> field? Is it believing that the field is a true/false container and  
> changes the default to a 0 (zero) since it is not a 1 (‘true’)?
> 
> Any ideas why this is happening and/or how to solve it short of  
> modifying the column’s length?

Well the mysql adapter has a MysqlAdapter.emulate\_booleans setting  
that does that with tinyint(1) columns.

The oracle adapter could conceivably be doing the same thing - check  
the source!

Fred

---

<div class="post-metadata">

**Author:** ![pepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4da419/32.png) [@pepe](https://www.ruby-forum.com/u/pepe)\
**Post date:** [September 5, 2008, 5:22pm UTC](https://www.ruby-forum.com/t/rails-overriding-database-default-value/147798/3 "2008-09-05T17:22:25Z")

</div>

Thanks Fred.

Pepe

On Sep 5, 9:42 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![pepe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/4da419/32.png) [@pepe](https://www.ruby-forum.com/u/pepe)\
**Post date:** [September 9, 2008, 4:56am UTC](https://www.ruby-forum.com/t/rails-overriding-database-default-value/147798/4 "2008-09-09T04:56:45Z")

</div>

Thanks Fred,

I found what I was looking for. I found the code for the adapter and  
these 2 lines are pretty revealing:

```
      return :boolean if OracleAdapter.emulate_booleans &&

```

field\_type == ‘NUMBER(1)’

```
    @@emulate_booleans = true

```

Thanks a lot for your help. 🙂

Pepe

On Sep 5, 9:42 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
