You could do something evil like this:
class MyModel < ActiveRecord::Base
def stupid_value
read_attribute(:stupid_value) * -1
end
def stupid_value=(val)
write_attribute(:stupid_value, (val * -1))
end
end
It''s not a great solution, but it should work.
--Jeremy
On Dec 20, 2007 3:50 PM, timo
<taylormiller-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> 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.
> >
>
--
http://www.jeremymcanally.com/
My books:
Ruby in Practice
http://www.manning.com/mcanally/
My free Ruby e-book
http://www.humblelittlerubybook.com/
My blogs:
http://www.mrneighborly.com/
http://www.rubyinpractice.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---