I was hoping 1.1 would provide a way to map SQL “decimal” column types
to BigDecimal values, since BigDecimal is part of the Ruby standard api
as of 1.8.
But I don’t see any support for that in the migration documentation, and
when I try to let Active Record do the mapping for me, it seems to
coerce the column into a Float (as the AwdwR book says).
Is it really there in 1.1 but I just don’t know what to do to tap into
it? Or is it still not part of ActiveRecord yet?
I’ve heard about Tobias’ “Money” plug-in but I’m not sure I want to go
that route unless I have to.
Storing money values should be very common - any shopping-cart style web
app will need to - but using floats can give rounding errors that can be
hard to spot (unlike the decimal type).
I was hoping 1.1 would provide a way to map SQL “decimal” column types
to BigDecimal values, since BigDecimal is part of the Ruby standard
api
as of 1.8.
Jeff
I missed this feature too - in fact it made Rails such a non-starter
at my company that I wrote a patch for ActiveRecord, which is
available at http://dev.rubyonrails.org/ticket/4274 . I wrote it
initially for Postgres and ported it to SQL Server (we are moving
from SQL Server to Postgres at work so they are the two databases I’m
familiar with). If you use either of these perhaps you’d give it a
try and let me know what you think. If I get time over the next few
weeks I’ll port it to Firebird and then MySQL. But really, you want
to be using Postgres for serious work
If I get time over the next few
weeks I’ll port it to Firebird and then MySQL. But really, you want
to be using Postgres for serious work
Hi Ashley,
Unfortunately I only use MySQL currently. If you do get a chance to
port it, just send an email to this list or to me directly and I’ll give
it a whirl.
Unfortunately I only use MySQL currently. Â If you do get a chance to
port it, just send an email to this list or to me directly and I’ll give
it a whirl.
Had a look at the MySQL adapter and it should be easy to get the numeric
precision and scale out of the database. If I’m not busy I’ll have a
look at
it over the weekend.
Last night I ported the decimal patch I’ve been working on to MySQL. If
you
want to try it you will need to freeze edge or gem into your application
directory, then apply the patch. Note that the PostgreSQL adapter has
recently been modified in the Rails trunk, so the patch will fail
against the
1.1 code (and I think 1.1.1 too). But this should not affect you using
MySQL.
Also, I still have to add two lines to SchemaDumper so it will dump the
precision and scale of decimals. This means that if you test an app
with
decimal columns, they will get the database default precision and scale.
I
didn’t notice this at first because I use Postgres, and that defaults to
using the maximum values available. However, SQL standard says the
scale
should default to 0, so you will end up with integers coming out of your
test
database. Just a heads up.
The patch has a full set of unit tests, but the plugin has none. I’ve
tried
it out with Postgres and it seems ok. SQL Server and MySQL may not work
if
I’ve copied something wrong.
Unfortunately I only use MySQL currently. If you do get a chance to
port it, just send an email to this list or to me directly and I’ll give
it a whirl.
Had a look at the MySQL adapter and it should be easy to get the numeric
precision and scale out of the database. If I’m not busy I’ll have a
look at
it over the weekend.
Ashley
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.