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.

:joins and :include behave differently with :conditions

#4472

When using a has_many :through, :conditions are applied differently for joins and includes.

The issue is related to applying the aliased table name to the condition has, and is only evident when two :has_many :through relationships use one :has_many as the :through.

Please refer to the attached file for a full example, or the gist found at http://gist.github.com/373613.

I am not sure how to create a test case for this issue but am happy to provide one if someone can give me some pointers.

Reported by Josh Kalderimis · April 25th, 2010 @ 03:28 PM

State: stale
Milestone: none
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Josh Kalderimis
    Josh Kalderimis
    • Tag changed from activerecord, associations, include, joins to 2.3.x, activerecord, associations, include, joins

    added related version tag

    April 25th, 2010 @ 03:29 PM

  2. Santiago Pastorino
    Santiago Pastorino

    Can you provide a test case?.
    Thanks.

    April 26th, 2010 @ 04:47 AM

  3. Josh Kalderimis
    Josh Kalderimis

    Hi Santiago,

    As I said in the issue, I am not sure how to create a test case for this issue, but I am happy to give it a stab if you can provide me with some pointers or another test which is similar and I can use as an example.

    Thanks,

    Josh

    April 26th, 2010 @ 09:11 AM

  4. Ryan Bigg
    Ryan Bigg

    If you're wanting to do conditions on another table you have to use joins rather than includes, as this will insert an SQL join. include is more for eager loading of potential records, where as joins will only load records that have that particular join.

    April 26th, 2010 @ 09:15 AM

  5. Ryan Bigg
    Ryan Bigg
    • Assigned user set to Pratik

    April 27th, 2010 @ 08:44 AM

  6. Josh Kalderimis
    Josh Kalderimis

    This issue is very similar to Issue 2908

    The core of the issue seems to be that the table alias name is not being applied to the conditions when using :joins

    April 29th, 2010 @ 09:25 AM

  7. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open
    • Tag changed from 2.3.x, activerecord, associations, include, joins to 23x, activerecord, associations, include, joins

    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 2nd, 2011 @ 04:51 PM

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

    February 2nd, 2011 @ 04:51 PM