This project is archived and is in readonly mode.
Limit failing on Arel Rails 3.0Beta
Reported by ronin-88709 (at lighthouseapp) | March 3rd, 2010 @ 02:33 AM | in 3.0.2
I've been puzzled over this, maybe I misunderstood something about chaining and Arel, it could be an issue.
scenario::
There are 250 comments for this current_user, id=1
@comments= Comment.where("user_id =?, current_user).limit(10)
when performing this with Rails 3.0.0Bet
a, Ruby 1.9.1 I get a result set of 250 and the limit fails
checking the output with to_sql and is seems correct
e.g => "SELECT comments
.* FROM
comments
WHERE (user_id =1) LIMIT 10"
but @comments.count comes up with 250 records.
with
@comments= Comment.find_by_sql("SELECT comments
.*
FROM comments
WHERE (user_id =1) LIMIT 10") I get the
expected 10 results...
I've searched all the tickets and cant seem to find any reference to this, I havent forked the latest beta3.0.1, and see no reference to this issue in the commits.
Comments and changes to this ticket
-
José Valim March 3rd, 2010 @ 09:09 AM
- Assigned user set to Pratik
- Milestone cleared.
Could you please try to reproduce this with a failing test case?
-
Denis Odorcic March 15th, 2010 @ 11:18 PM
I'm pretty sure this is not a bug but just a bit confusing when using 'count'.
@comments = Comment.where("user_id = ?", current_user).limit(10) @comments.count returns 250 records because I'm guessing your sql looks something like this
SELECT COUNT(comments.*) FROM comments WHERE (user_id =1) LIMIT 10 and if you try that sql statement out raw you'll see it returns 250.
I think the ruby community is used to doing a .count on an array and getting back the size but its different here.
Now if you did @comments.all.count (or size), you'd get your expected result. -
José Valim March 15th, 2010 @ 11:21 PM
- State changed from new to invalid
OdorcicD, thanks for stepping in. You are right! Marking as invalid.
-
Ryan Bigg October 9th, 2010 @ 10:10 PM
- Tag cleared.
- Importance changed from to Low
Automatic cleanup of spam.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>