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.

fixed counter_sql from finder_sql to work with subselects

#2802

This patch allows to use subselects in the finder_sql without specifing the counter_sql which was impossible because the regex was too greedy. The patch fixes this issue for has_many, has_many :through and has_and_belongs_to_many.
Tests included.

Reported by Kane · June 14th, 2009 @ 06:27 PM

State: stale
Milestone: 3.x
Assigned to: Jeremy Kemper Jeremy Kemper
Importance: none

Activity

  1. Pratik
    Pratik

    Hey,

    The patch doesn't apply cleanly. Also, could you please fix your email in the patch ?

    git config --global user.name "Your Name"
    git config --global user.email your_email@your-domain.com
    

    June 22nd, 2009 @ 10:04 AM

  2. Kane
    Kane
    • Assigned user set to Pratik

    July 21st, 2009 @ 10:55 PM

  3. Pratik
    Pratik
    • State changed from new to incomplete

    Hey Kane,

    The tests fail on sqlite3. I think the test should be skipped for adapters not supporting subqueries.

    Thanks!

    July 29th, 2009 @ 06:56 PM

  4. Kane
    Kane

    are there adapters which dont support subqueries?

    I changed the sql, now works with sqlite3 and should not be adapter specific.

    hope this is the final version^^

    July 29th, 2009 @ 09:36 PM

  5. Pratik
    Pratik

    The test still fails for me on sqlite3.

      1) Error:
    test_counting_from_finder_sql_with_subselect(HasManyAssociationsTest):
    ActiveRecord::StatementInvalid: SQLite3::SQLException: near ")": syntax error: SELECT COUNT(*) FROM companies LIMIT 1) IS NOT NULL;
        ./cases/../../lib/active_record/connection_adapters/abstract_adapter.rb:214:in `log'
        ./cases/../../lib/active_record/connection_adapters/sqlite_adapter.rb:168:in `execute_without_query_record'
        ./cases/../../lib/active_record/connection_adapters/sqlite_adapter.rb:413:in `catch_schema_changes'
        ./cases/../../lib/active_record/connection_adapters/sqlite_adapter.rb:168:in `execute_without_query_record'
        ./cases/helper.rb:41:in `execute'
        ./cases/../../lib/active_record/connection_adapters/sqlite_adapter.rb:316:in `select'
        ./cases/../../lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache'
        ./cases/../../lib/active_record/connection_adapters/abstract/query_cache.rb:62:in `select_all'
        ./cases/../../lib/active_record/connection_adapters/abstract/database_statements.rb:13:in `select_one'
        ./cases/../../lib/active_record/connection_adapters/abstract/database_statements.rb:19:in `select_value'
        ./cases/../../lib/active_record/base.rb:956:in `count_by_sql'
        ./cases/../../lib/active_record/associations/association_collection.rb:169:in `count'
        cases/associations/has_many_associations_test.rb:36:in `test_counting_from_finder_sql_with_subselect'
        ./cases/../../lib/../../activemodel/lib/../../activesupport/lib/active_support/testing/setup_and_teardown.rb:62:in `__send__'
        ./cases/../../lib/../../activemodel/lib/../../activesupport/lib/active_support/testing/setup_and_teardown.rb:62:in `run'
    

    July 30th, 2009 @ 01:33 PM

  6. Kane
    Kane

    strange, i only get this error without the fix.

    August 1st, 2009 @ 01:11 PM

  7. Kane
    Kane

    i rebased and removed a conflict.

    also 2 other developers tried my patch and they got no error.
    i have no idea why its failing on your machine.

    tested on:
    windows xp, ruby 1.8.6, sqlite3-ruby 1.2.5 with sqlite 3.5.6
    ubuntu, ruby 1.9.1, sqlite3-ruby 1.2.4 with sqlite 3.6.10

    August 24th, 2009 @ 11:54 PM

  8. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  9. Kane
    Kane

    this is still an issue in edge..

    June 22nd, 2010 @ 07:36 PM

  10. Kane
    Kane
    • Assigned user changed from Pratik to Jeremy Kemper

    June 22nd, 2010 @ 07:36 PM

  11. Neeraj Singh
    Neeraj Singh
    • Importance changed from to

    @Kane can you provide an example of "subselects in the finder_sql" so I could fully understand the problem this patch is solving. If I understand it then I can write a test for your patch.

    Thanks

    July 2nd, 2010 @ 03:39 AM

  12. Kane
    Kane

    SELECT * FROM articles WHERE id IN (SELECT article_id FROM comments WHERE text LIKE '%test%');

    August 2nd, 2010 @ 06:24 PM

  13. rails
    rails
    • State changed from incomplete 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 26th, 2011 @ 12:00 AM

  14. rails
    rails
    • State changed from open to stale

    February 26th, 2011 @ 12:00 AM