This project is archived and is in readonly mode.

#3121 ✓stale
tim

ActiveRecord::Base.find mixed array of Strings and Symbols for :joins option

Reported by tim | August 31st, 2009 @ 02:47 PM

added support for mixed arrays of manueal joins and model associations in ActiveRecord::Base.find's :joins option

Right now it is only possible to eather supply Strings with handcoded sql join options or an Array/Hash with References to model associations. But it is not possible for example to say :joins => [:person, "ratings inner join post on ratings.post_id = posts.id"]

But when you have a polymorphic association, just adding the association does not work. You have to code the join yourself in sql. Then it is really handy to mix both.

a next step should be to support automatic joins with polymorphic associations, by specifing which of the polymorphic association is wanted PolymorphicComment.all( :joins => {:polymorphic_commentable => :for_posts} )

Comments and changes to this ticket

  • David Trasbo

    David Trasbo April 12th, 2010 @ 10:44 AM

    +1

    I can definitely see cases where this patch would come in handy. Also, it makes the :joins option behave like you would expect it.

  • Will Bryant

    Will Bryant May 26th, 2010 @ 05:27 AM

    Guys, is this still needed with 3.0's new arel-based join goodness? The new query building lets you specify the joins one by one building on the relations, so AFAIK you won't need this feature any more.

  • Uwe Kubosch

    Uwe Kubosch July 19th, 2010 @ 11:55 AM

    • Importance changed from “” to “”

    2.3 will be around for a long time, and the "old" way of calling find with :joins will be used for a long time.

    The patch is very small and simple. Please add this patch.

  • EJ Finneran

    EJ Finneran January 18th, 2011 @ 10:49 PM

    Also, whether the patch goes in or not, I noticed that the Rails 2.3 docs claim this is already supported:

    http://railsapi.com/doc/v2.3.2/

    :joins - Either an SQL fragment for additional joins like "LEFT JOIN comments ON comments.post_id = id" (rarely needed), named associations in the same form used for the :include option, which will perform an INNER JOIN on the associated table(s), or an array containing a mixture of both strings and named associations. If the value is a string, then the records will be returned read-only since they will have attributes that do not correspond to the table‘s columns. Pass :readonly => false to override.

  • rails

    rails April 19th, 2011 @ 01:00 AM

    • 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.

  • rails

    rails April 19th, 2011 @ 01:00 AM

    • 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