Hello everyone, I've got a question for the ActiveRecord gurus.
ActiveRecord version: 2.3.4 ActiveRecord adapter: mysql
I'm accessing a database originally designed as the back-end data- store for a Microsoft Access-based GUI application (using "linked" tables). MS Access, if using linked tables to use a MySQL database wants its boolean fields, like ActiveRecord, to by TINYINT(1) fields. However, is makes the field "signed" and uses 0 for false and -1 for true.
I've taken several approaches to interfacing with boolean fields in this database in an interoperable way (keeping boolean true values as -1). What seems like it should be so easy/simple has yet yield a clean solution (to me at least).
My Example Table (tblImages):
ImageID, UNSIGNED INTEGER, AUTOINCREMENT, PRI-KEY IsFixed, TINYINT, DEFAULT 0
ActiveRecord class:
class Image < ActiveRecord::Base set_table_name 'tblImages' set_primary_key 'ImageID' def fixed self.IsFixed_before_type_cast == "-1" end def fixed=(val) self[:IsFixed] = (val ? '-1' : '0') end end
The above code is just one of the many approaches I've taken. I always get so close yet so far. Reading the value is easy by getting it prior to type-casting and interpreting it how I want. However, coercing ActiveRecord (and the MySQL adapter) to issue an "UPDATE tblImage SET IsFixed = -1 ..." seem all but impossible when I issue a save! on an instance.
So, is there any way to tell ActiveRecord (or the MySQL adapter) to simply disable its boolean emulation on a given field (or even the whole table or database)? Or, does anyone have any alternate ideas that might work instead or even better?
Thanks for your help!