Forum: Ruby on Rails Changing the ActiveRecord mapping of boolean values in the DB ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Thomas W. (Guest)
on 2009-04-26 15:35
(Received via mailing list)
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
Roderick v. (Guest)
on 2009-04-26 15:40
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
http://www.nedforce.nl
This topic is locked and can not be replied to.