# Custom Boolean Definition

**URL:** <https://discuss.rubyonrails.org/t/custom-boolean-definition/22049>\
**Category:** rubyonrails-talk\
**Created:** [December 20, 2007, 8:50pm UTC](https://discuss.rubyonrails.org/t/custom-boolean-definition/22049 "2007-12-20T20:50:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![timo](https://avatars.discourse-cdn.com/v4/letter/t/c4cdca/32.png) [@timo](https://discuss.rubyonrails.org/u/timo)\
**Post date:** [December 20, 2007, 8:50pm UTC](https://discuss.rubyonrails.org/t/custom-boolean-definition/22049/1 "2007-12-20T20:50:35Z")

</div>

Greetings.

I have a legacy database that cannot be changed. The true/false values in the database are true = -1, false = 0 (Thank you very much VB...) Unfortunately, when I interact with these, rails/ruby sees everything as false, which causes all sorts of havoc.

Is there a way to define (in my model or elsewhere) true as -1 instead of 1?

or

Is there a way to access the true/false field as an integer so I can manually test for true/false by

if customer.some\_field == -1 then...

Thanks for your help. The lifeline of my project / job depend on making this work.

---

<div class="post-metadata">

**Author:** ![Jeremy\_McAnally](https://avatars.discourse-cdn.com/v4/letter/j/c89c15/32.png) [@Jeremy\_McAnally](https://discuss.rubyonrails.org/u/Jeremy_McAnally)\
**Post date:** [December 20, 2007, 8:57pm UTC](https://discuss.rubyonrails.org/t/custom-boolean-definition/22049/2 "2007-12-20T20:57:11Z")

</div>

You could do something evil like this:

&nbsp;&nbsp;class MyModel \< ActiveRecord::Base &nbsp;&nbsp;&nbsp;&nbsp;def stupid\_value &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;read\_attribute(:stupid\_value) \* -1 &nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;def stupid\_value=(val) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;write\_attribute(:stupid\_value, (val \* -1)) &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;end

It's not a great solution, but it should work.

--Jeremy
