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.

SomeModel.select fails to limit field with includes

#5898

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

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

State: stale
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Eugene Magdel
    Eugene Magdel

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

    October 30th, 2010 @ 09:43 PM

  2. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Importance changed from to Low

    Automatic cleanup of spam.

    November 1st, 2010 @ 05:01 PM

  3. x37v
    x37v

    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)

    November 4th, 2010 @ 04:53 PM

  4. Neeraj Singh
    Neeraj Singh

    @Eugene

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

    November 10th, 2010 @ 09:52 PM

  5. Santiago Pastorino
    Santiago Pastorino
    • 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.

    February 11th, 2011 @ 07:18 PM

  6. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 11th, 2011 @ 07:18 PM