Project

General

Profile

Bug #11924

Substitute .scoped by .where(nil) to force return relation

Added by Daniel Lobato Garcia almost 4 years ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Category:
Rails
Target version:
Difficulty:
Triaged:
Bugzilla link:
Team Backlog:
Fixed in Releases:
Found in Releases:

Description

On Rails 4 .scoped is deprecated. Calling .all on the model returns the equivalent ActiveRecord relation object on Rails 4, but on Rails 3 it returns an Array right away.
A proper replacement we can use is where(nil) - it's ugly but it returns the same relation in both Rails 3 and 4.
We could possibly substitute these by .all after the Rails 4 migration if they feel too 'unidiomatic'.


Related issues

Related to Foreman - Tracker #3157: Rails 4.1 upgrade tasksClosed2013-09-27

Related to Foreman - Bug #12432: User edit roles tab, no roles found for admin userClosed2015-11-10

Associated revisions

Revision 02e4c535 (diff)
Added by Daniel Lobato Garcia almost 4 years ago

Fixes #11924 - Substitute .scoped by .where(nil) to force return relation

On Rails 4 .scoped is deprecated. Calling .all on the model returns the
equivalent ActiveRecord relation object on Rails 4, but on Rails 3 it
returns an Array right away.

A proper replacement we can use is where(nil) - it's ugly but it returns
the same relation in both Rails 3 and 4. There are a couple of fixes too
on models such as bookmark.rb which return where conditions ({} and
similar) instead of a relation, which is also a deprecated behavior.

We could possibly substitute these by .all after the Rails 4 migration
if they feel too 'unidiomatic'.

History

#1 Updated by Daniel Lobato Garcia almost 4 years ago

  • Subject changed from Substitute scoped for where(nil) to force return relation to Substitute .scoped by .where(nil) to force return relation

#2 Updated by The Foreman Bot almost 4 years ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/2754 added
  • Pull request deleted ()

#3 Updated by Daniel Lobato Garcia almost 4 years ago

#4 Updated by Dominic Cleal almost 4 years ago

  • Assignee set to Daniel Lobato Garcia
  • Legacy Backlogs Release (now unused) set to 71

#5 Updated by Daniel Lobato Garcia almost 4 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#6 Updated by Dominic Cleal almost 4 years ago

  • Related to Bug #12432: User edit roles tab, no roles found for admin user added

Also available in: Atom PDF