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.

ActiveRecord::Base.joins no longer accepts nil

#6181

A break with previous functionality was introduced with Aaron Patterson's recent change to joins, found here:

https://github.com/rails/rails/commit/d98cb5153dad97cde82ec91a1993043cfa9bc0e4

ActiveRecord's joins method no longer accepts either nil or [nil], which breaks some applications that depended on that. Specifically, CanCan's ActiveRecord::Base.accessible_by method now breaks if there are no joins.

https://github.com/ryanb/cancan/blob/master/lib/cancan/active_record_additions.rb

ActiveRecord where(nil), on the other hand, returns a result.

Reported by Matthew Ratzloff · December 16th, 2010 @ 07:02 PM

State: resolved
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Matthew Ratzloff
    Matthew Ratzloff

    So basically, you just need to call Array#compact on it before handling it in ActiveRecord::QueryMethods.joins. This fixes the issue.

    I've attached a monkey patch for others having trouble.

    December 16th, 2010 @ 08:38 PM

  2. Repository
    Repository
    • State changed from new to resolved

    (from [40b15f9f389b9394b22cf36567269e54c66c9fc8]) ActiveRecord::Base.joins should allow single nil argument [#6181 state:resolved] https://github.com/rails/rails/commit/40b15f9f389b9394b22cf36567269...

    December 16th, 2010 @ 09:27 PM

  3. Matthew Ratzloff
    Matthew Ratzloff

    That fixed it. Thanks, Piotr!

    December 16th, 2010 @ 11:50 PM