This project is archived and is in readonly mode.

#5898 ✓stale
Eugene Magdel

SomeModel.select fails to limit field with includes

Reported by Eugene Magdel | October 30th, 2010 @ 09:41 PM

ProcessedTransaction.select("raw_transactions.id").where("raw_transactions.id <> 1").includes(:raw_transaction).limit(1)
yields
RECEIVED:
[#] EXPECTED:
[#<raw_transaction_id: 38058>]

Associations
raw_transactions has_one processed_transaction

Comments and changes to this ticket

  • Eugene Magdel

    Eugene Magdel October 30th, 2010 @ 09:43 PM

    RECEIVED:
    [# ProcessedTransaction id: 76105, raw_transaction_id: 38058, category_id: nil, amount: -21588, transaction_order: 0, automatic_fill: false ]

  • Jeff Kreeftmeijer

    Jeff Kreeftmeijer November 1st, 2010 @ 05:01 PM

    • Importance changed from “” to “Low”

    Automatic cleanup of spam.

  • x37v

    x37v November 4th, 2010 @ 04:53 PM

    I've noticed the same thing with .joins + .limit

    I've created a test app (attached) which shows the problems [test/unit/user_test.rb]

    This FAILS:
    assert_equal User.find_by_sql(User.joins(:user_foo).limit(12).to_sql).size, User.joins(:user_foo).limit(12).size

    On the console, oddly, if I assign the Relation to a variable and then test .size on it, I get the correct result.

    in the console rails c test:

    u = User.joins(:user_foo).limit(12) => ....
    u.size => 12
    u.size == User.joins(:user_foo).limit(12).size => false

    But in the test this fails:
    u = User.joins(:user_foo).limit(12)
    assert_equal 12, u.size

    In the mean time, a work around, is to wrap in User.find_by_sql(User.joins(:user_foo).limit(12).to_sql)

  • Neeraj Singh

    Neeraj Singh November 10th, 2010 @ 09:52 PM

    @Eugene

    Can you post migration and model for the ProcessedTransaction and RawTransaction? I will look into this issue.

  • Santiago Pastorino

    Santiago Pastorino February 11th, 2011 @ 07:18 PM

    • State changed from “new” to “open”

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 11th, 2011 @ 07:18 PM

    • State changed from “open” to “stale”

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>

Attachments

Pages