
Chained finders being isolated
Reported by ash.gti | June 20th, 2009 @ 08:46 PM | in 0.10.0
Currently in both 0.9.11 and 0.10.0 if you try to chain a finder it does not isolate the queries.
For instance, if you did
Model.all(:count.gt => 5).all(:conditions => ['name != ? OR name != ?', 'Joe', 'Steve'])
You'd expect there WHERE to be close to:
SELECT * FROM model WHERE (count > 5) AND (name != 'Joe' OR name != 'Steve')
However, currently the query would look like:
SELECT * FROM model WHERE count > 5 AND name != 'Joe' OR name != 'Steve'
and clearly in that query the OR statement needs parenthesis around it or else your going to get results you wouldn't normally expect. This issue doesn't really crop up unless you have an OR in your query, but I think its still an issue.
Here is a gist that I hope clearly demonstrates the issue: http://gist.github.com/133351
Comments and changes to this ticket
-
Dan Kubb (dkubb) June 20th, 2009 @ 10:45 PM
- Assigned user set to Dan Kubb (dkubb)
- State changed from new to accepted
I agree, this is a problem that should be resolved. I think we should either wrap the raw conditions in parenthesis at all times, or at the very least when they have an OR condition (and probably NOT condition too, but I'm not sure if NOT applies to the next statement or all following statements).
-
Dan Kubb (dkubb) June 23rd, 2009 @ 03:00 AM
- State changed from accepted to resolved
(from [91f6fd40b4f98b4b36feddf3433db653182c87ea]) Explicitly wrap all raw queries in parenthesis
- Prevents potential problems with OR conditions and other operators applying to more than just the intended statement
[#915 state:resolved] http://github.com/datamapper/dm-core/commit/91f6fd40b4f98b4b36feddf...
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
People watching this ticket
Referenced by
-
915 Chained finders being isolated [#915 state:resolved] http://github.com/datamapper/dm-co...