プロジェクト

全般

プロフィール

Vote #72898

完了

Use lambda in model scopes

Admin Redmine さんが約4年前に追加. 約4年前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Plugin API_20
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
20
version_id:
60
issue_org_id:
12499
author_id:
1188
assigned_to_id:
1188
comments:
5
status_id:
5
tracker_id:
3
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

Yesterday I had to monkey-patch "Group" in a plugin, and it turned out to be really difficult because there's a scope defined in the Group class which doesn't use lambda. In this case, the scope is evaluated directly, which fails with "Could not find table users" for instance if you're in a "db:migrate" phase and your database is empty.

Hence I propose moving all scopes to their lambda form so that these difficulties disappear for plugin development.

One more thing, using scopes without lambda (or a call-able) will be deprecated in Rails 4 and probably removed in Rails 4.1 (see "this commit":https://github.com/rails/rails/commit/0a12a5f8169685915cbb7bf4d0a7bb482f7f2fd2).

Let me know what you think. If you're OK with this change I can take care of verifying all models, running tests and making the change everywhere...


journals

If you want to see what's involved, here are the two commits on my plugin : "one":https://github.com/jbbarth/redmine_organizations/commit/64a3bd7f1559354a11d7231a850a6cedab1742af, "two":https://github.com/jbbarth/redmine_organizations/commit/a7d19ed4e09df6c96ecb317593c0a97a650d3bec (but please don't start me on the bad idea of monkey patching core classes, that's all I have now to accomplish this kind of change...)
--------------------------------------------------------------------------------
Looks ok to me, should be marked as a deprecated usage in RoR, too bad it is not?
--------------------------------------------------------------------------------
Agreed.
--------------------------------------------------------------------------------
Done in r10949. I left scopes in the same form they used before (some use Arel syntax, some use the rails 2 hash syntax) but I might dig into that later.
--------------------------------------------------------------------------------
Jean-Baptiste Barth wrote:
> Done in r10949. I left scopes in the same form they used before (some use Arel syntax, some use the rails 2 hash syntax) but I might dig into that later.

Thanks, scopes now use Arel BTW (r10950).
--------------------------------------------------------------------------------

Admin Redmine さんが約4年前に更新

  • カテゴリPlugin API_20 にセット
  • 対象バージョン2.3.0_60 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0