Comments (7)
----- Original Message -----
From: "SteveFenn" [email protected]
To: [email protected]
Sent: Monday, September 5, 2011 6:27:07 PM
Subject: [scoped_search] Issue with DECIMAL columns and MySQL (#12)
HeyI have just started using the gem and it's great!
Whilst using it I have encountered a problem with scoped_search on
decimals. I've isolated my problem down to the simple test case below:class Order < ActiveRecord::Base
scoped_search :on => :total
end
"total" is a DECIMAL column within the database, then running this
line within console:Order.search_for("123.12")
Gives these results in the development log:
Order Load (65.0ms) SELECT * FROM
orders
WHERE (orders
.total
=
123)It seems that at some point my search number is being converted into
an integer. I believe this should be querying for "orders
.total
=
123.12". As the moment, the query is, of course, effectively looking
for values of 123.00, and hence is not finding the order I'm looking
for.I am using rails version 2.3.10, scoped_search version 2.3.1 and I am
using MySQL.I apologise if this post doesn't make sense.
Thanks for the plugin,
SteveReply to this email directly or view it on GitHub:
#12
Thanks for reporting the problem.
I'll try to reproduce it and will get back to you as soon as I have results.
Amos.
from scoped_search.
----- Original Message -----
From: "SteveFenn" [email protected]
To: [email protected]
Sent: Monday, September 5, 2011 6:27:07 PM
Subject: [scoped_search] Issue with DECIMAL columns and MySQL (#12)
HeyI have just started using the gem and it's great!
Whilst using it I have encountered a problem with scoped_search on
decimals. I've isolated my problem down to the simple test case below:class Order < ActiveRecord::Base
scoped_search :on => :total
end
"total" is a DECIMAL column within the database, then running this
line within console:Order.search_for("123.12")
Gives these results in the development log:
Order Load (65.0ms) SELECT * FROM
orders
WHERE (orders
.total
=
123)It seems that at some point my search number is being converted into
an integer. I believe this should be querying for "orders
.total
=
123.12". As the moment, the query is, of course, effectively looking
for values of 123.00, and hence is not finding the order I'm looking
for.I am using rails version 2.3.10, scoped_search version 2.3.1 and I am
using MySQL.I apologise if this post doesn't make sense.
Thanks for the plugin,
SteveReply to this email directly or view it on GitHub:
#12
Hi Steve,
I have found the following suggestion in a blog:
...
Check the definition of the table in Mysql, chances are you have a decimal column with no decimal "scale" set.
By default, if you don't tell Mysql ho many decimal places to use it will have none, and ActiveRecord will then simply interpret that as an Integer.
Update you column with a migration like this:
change_column('table_name', 'colun_name', :decimal, { :scale => 2, :precision => 10 } )
See original post here:
http://n4k3d.com/blog/post/18/activerecord_magically_changing_decimal_columns_to_integers/
Please update me if this solves your issue.
Thanks,
Amos.
from scoped_search.
Hi Amos,
Thanks for getting back so quickly
I've taken a look, and the column is a decimal - it's got :precision => 8, :scale => 3 I should have put this in the original post.
The regular Rails finders seem to work fine:
$ Order.find_by_total(123.12)
This gives this result in the development log:
=> SELECT * FROM `orders` WHERE (`total` = 123.12) LIMIT 1
Checked order.total as well:
$ Order.first.total.class
=> BigDecimal
Thank you again for looking into this
Steve
from scoped_search.
----- Original Message -----
From: "SteveFenn" [email protected]
To: [email protected]
Sent: Tuesday, September 6, 2011 11:25:56 AM
Subject: Re: [scoped_search] Issue with DECIMAL columns and MySQL (#12)
Hi Amos,Thanks for getting back so quickly
I've taken a look, and the column is a decimal - it's got :precision
=> 8, :scale => 3 I should have put this in the original post.The regular Rails finders seem to work fine:
$ Order.find_by_total(123.12)
This gives this result in the development log:
=> SELECT * FROM
orders
WHERE (total
= 123.12) LIMIT 1Checked order.total as well:
$ Order.first.total.class
=> BigDecimalThank you again for looking into this
SteveReply to this email directly or view it on GitHub:
#12 (comment)
Hi Steve,
I have managed to reproduce the issue.
It is now fixed and I have added a relevant test.
Thanks again for reporting the issue.
The fix will be available shortly in the gem release.
Thanks,
Amos.
from scoped_search.
Hi Amos,
Thanks for looking into this and fixing it, Its a great plugin
When the gem release comes out I will test and confirm it fixes problem
Thanks,
Steve
from scoped_search.
fixed in release 2.3.3
from scoped_search.
Hey
This has fixed the original problem we were having,
Thanks again
from scoped_search.
Related Issues (20)
- Searching for future dates by relative days HOT 5
- Request for new gem release HOT 3
- A new release required HOT 5
- Exception when searching for words together with a field defined with ext_method HOT 1
- Question: Can the advanced query language be disabled? HOT 1
- Not compatible with Postgres citext column type HOT 4
- Problems searching for resources belonging to STI
- exception during autocomplete for virtual field not defined in DB HOT 8
- Query language - Temporal comparisons do not support seconds
- Postgres adapter not picked up when using PostGIS HOT 1
- "scoped_search relation:" does not pay attention to "has_many ..., primary_key:" overrides. HOT 1
- Boolean fields with complete_value hash generates AR::PreparedStatementInvalid exceptions
- undefined method `join_keys' for class `ActiveRecord::Reflection::HasManyReflection' - ActiveRecord 6.1 HOT 4
- has_rich_text relation is not supported HOT 4
- "undefined method `to_sym' for {:on=>:looking_for}:Hash\nDid you mean? to_s\n to_set" HOT 2
- Deprecated functionality for Ruby 2.7 HOT 7
- Optional sanitizing of _ and % in search values
- scoped_search not working with Ruby 3.0.2 HOT 6
- rubygems.org version differs from master branch, Ruby 3 support not included HOT 2
- Inconsistency in quoted field name interpretation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scoped_search.