Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Limit failing on Arel Rails 3.0Beta

#4096

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.

Reported by ronin-88709 (at lighthouseapp) · March 3rd, 2010 @ 02:33 AM

State: invalid
Milestone: 3.0.2
Assigned to: Pratik Pratik
Importance: Low

Activity

  1. José Valim
    José Valim
    • Assigned user set to Pratik
    • Milestone cleared.

    Could you please try to reproduce this with a failing test case?

    March 3rd, 2010 @ 09:09 AM

  2. Denis Odorcic
    Denis Odorcic

    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.

    March 15th, 2010 @ 11:18 PM

  3. José Valim
    José Valim
    • State changed from new to invalid

    OdorcicD, thanks for stepping in. You are right! Marking as invalid.

    March 15th, 2010 @ 11:21 PM

  4. Ryan Bigg
    Ryan Bigg
    • Tag cleared.
    • Importance changed from to Low

    Automatic cleanup of spam.

    October 9th, 2010 @ 10:10 PM

  5. Ryan Bigg
    Ryan Bigg

    Automatic cleanup of spam.

    October 11th, 2010 @ 12:12 PM

  6. Jeremy Kemper
  7. Ryan Bigg
    Ryan Bigg

    Automatic cleanup of spam.

    October 21st, 2010 @ 03:36 AM

  8. Jeff Kreeftmeijer