# Changing the ActiveRecord mapping of boolean values in the DB?

**URL:** <https://www.ruby-forum.com/t/changing-the-activerecord-mapping-of-boolean-values-in-the-db/166502>\
**Category:** Rails\
**Created:** [April 26, 2009, 1:35pm UTC](https://www.ruby-forum.com/t/changing-the-activerecord-mapping-of-boolean-values-in-the-db/166502 "2009-04-26T13:35:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/848f3c/32.png) [@wet](https://www.ruby-forum.com/u/wet)\
**Post date:** [April 26, 2009, 1:35pm UTC](https://www.ruby-forum.com/t/changing-the-activerecord-mapping-of-boolean-values-in-the-db/166502/1 "2009-04-26T13:35:11Z")

</div>

Hi,

I want to insert some rows into a sqlite3 database where some tables  
contain BOOLEAN columns.

Some older applications accessing the same DB require boolean columns  
to be 0 and 1, whereas the default behaviour of the sqlite Adapter is  
a mapping of true/false values to ‘t’ and ‘f’ in the database.

My current workaround is a row insert trigger in the database, but I’d  
rather have this logic in the AR model class.

Is there some way to change the type mapping on model level ?

Thanks and kind regards,  
Thomas

---

<div class="post-metadata">

**Author:** ![wet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/848f3c/32.png) [@wet](https://www.ruby-forum.com/u/wet)\
**Post date:** [April 26, 2009, 1:40pm UTC](https://www.ruby-forum.com/t/changing-the-activerecord-mapping-of-boolean-values-in-the-db/166502/2 "2009-04-26T13:40:29Z")

</div>

Thomas Waswasi wrote:

> I want to insert some rows into a sqlite3 database where some tables  
> contain BOOLEAN columns.
> 
> Some older applications accessing the same DB require boolean columns  
> to be 0 and 1, whereas the default behaviour of the sqlite Adapter is  
> a mapping of true/false values to ‘t’ and ‘f’ in the database.
> 
> My current workaround is a row insert trigger in the database, but I’d  
> rather have this logic in the AR model class.
> 
> Is there some way to change the type mapping on model level ?

Not on the model level, but you could monkey-patch the AR quoting  
function.

–  
Roderick van Domburg

> **[De domeinnaam Nedforce.nl is te koop.](http://www.nedforce.nl)**
>
> Deze mooie domeinnaam kan al over een paar minuten van jou zijn. Betalen gaat eenvoudig en vertrouwd via iDEAL. Direct na de betaling ontvang je de verhuiscode per e-mail en kun je aan de slag.
