プロジェクト

全般

プロフィール

Vote #71962

完了

UserCustomField order_statement returns wrong output

Admin Redmine さんが3年以上前に追加. 3年以上前に更新.

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

0%

予定工数:
category_id:
14
version_id:
47
issue_org_id:
11073
author_id:
54319
assigned_to_id:
6508
comments:
7
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[Closed]

説明

The UserCustomField order_statement returns wrong output:

Eg:
For a user custom field named "Employee Code" (type string) the order statement is returned as follows:

@>> UserCustomField.find_by_name("Employee Code").order_statement
=> "COALESCE((SELECT cv_sort.value FROM custom_values cv_sort WHERE cv_sort.customized_type='User' AND cv_sort.customized_id=users.id AND cv_sort.custom_field_id=1 LIMIT 1), '')"@

Herein the value of customized_type is User, whereas in the actual database table, i.e. custom_values table, the value of customized_type for UserCustomFields is Principal (which is a superclass of User class).

For this reason, the UserCustomField.find_by_name("Employee Code").order_statement gives a statement which always returns empty output when used in a query.

The correct value of UserCustomField.find_by_name("Employee Code").order_statement should be:

@>> UserCustomField.find_by_name("Employee Code").order_statement
=> "COALESCE((SELECT cv_sort.value FROM custom_values cv_sort WHERE cv_sort.customized_type='Principal' AND cv_sort.customized_id=users.id AND cv_sort.custom_field_id=1 LIMIT 1), '')"@


journals

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
A suggested patch has been attached:

File to be patched:

@app/models/custom_field.rb@
--------------------------------------------------------------------------------
Rails stores the base class type (@Principal@) instead of the actual class type (@User@).

These RoR issues might be relevant:

https://rails.lighthouseapp.com/projects/8994/tickets/5617
https://github.com/rails/rails/issues/724 (continuation of lh 5617)
https://github.com/rails/rails/issues/617

--------------------------------------------------------------------------------
Maybe you can try to replace @self.class.customized_class.name@ with @self.class.customized_class.base_class.name@?
--------------------------------------------------------------------------------
Should be fixed with r9880, thanks for the report.

I don't know if it's useful to write a test since this statement is not used in Redmine code to query User model nor where I should write it?
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------


related_issues

relates,Closed,1139,Being able to sort the issue list by custom fields

Admin Redmine さんが3年以上前に更新

  • カテゴリCustom fields_14 にセット
  • 対象バージョン2.1.0_47 にセット

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

いいね!0
いいね!0