カスタム・フィールドのデータ取り出しについて

1,695 views
Skip to first unread message

taken

unread,
Aug 17, 2008, 1:41:36 AM8/17/08
to Redmine Users (japanese)
Redmine 0.7.1 (MySQL) を Ubuntu 8.04 Server で使用しています。

メールを Mailing list へ送信するようにしたいため、以下を参照してパッチをあてました。

http://fmkt.dip.jp/cgi-bin/bloq/blog.cgi?n=348&category=009
> redmineからのメールをMailinglistに

# これは 0.6.0 のもののようです。

Redmine 0.7.1 では、パッチにある app/models/project.rb の mailing_list で
custom_values.find で値がとれていないように思えます。

プロジェクトには、カスタム・フィールドの "Mailing list" は追加してあります。メールアドレスも入力してあります。

このあたりの、カスタム・フィールドのデータ取り出しについて、なにかご存知の方がいらっしゃいましたら、ご教示お願いします m(__)m

fmkt

unread,
Aug 17, 2008, 9:47:19 PM8/17/08
to Redmine Users (japanese)
こんにちは。

custom_values.find で値がとれていないということですが、
script/console 上で CustomValue.find(:all) とか
Project.find(hoge).custom_values.find(:all) 、
また conditions を入れて試されても値は取れないでしょうか?

ご確認の方よろしくお願いします。

では。



taken

unread,
Aug 18, 2008, 7:34:53 AM8/18/08
to Redmine Users (japanese)
fmkt さん、コメントありがとうございます m(__)m 以下のようになりました。

アレ? これだと custom_values が未定義ということになるんでしょうか。

--- ここから
$ sudo RAILS_ENV=production ruby ./script/console
Loading production environment (Rails 2.0.2)
>> CustomValue.find(:all)
=> [#<CustomValue id: 655, customized_type: "Issue", customized_id:
44, custom_field_id: 7, value: "">, #<CustomValue id: 656,
customized_type: "Issue", customized_id: 44, custom_field_id: 8,
value: "">, #<CustomValue id: 657, customized_type: "Issue",
customized_id: 44, custom_field_id: 13, value: "">, #<CustomValue id:
658, customized_type: "Issue", customized_id: 44, custom_field_id: 14,
value: "">, #<CustomValue id: 659, customized_type: "Issue",
customized_id: 44, custom_field_id: 15, value:
"foo...@ml.foobar.com">]
>> Project.find(:first).custom_values.find(:all)
=> []
>> Project.find(:all).custom_values.find(:all)
NoMethodError: undefined method `custom_values' for #<Array:
0xb6eea974>
from (irb):3
>> quit
$
--- ここまで


念のため、カスタム・フィールドを追加してチケットを発行したさいの、log/production.log の一部も掲載します。


--- ここから
$ tail -20 log/production.log
Session ID: d8a35d6f5e821698f9c4593b56237443
Parameters: {"project_id"=>"test", "action"=>"new",
"controller"=>"issues"}
Rendering template within layouts/base
Rendering issues/new
Completed in 0.09194 (10 reqs/sec) | Rendering: 0.04519 (49%) | DB:
0.00000 (0%) | 200 OK [http://xxxxxx.xxxx.xxxx.xx/redmine/demo/
projects/test/issues/new]


Processing IssuesController#new (for xxx.xxx.xxx.xx at 2008-08-18
14:36:02) [POST]
Session ID: d8a35d6f5e821698f9c4593b56237443
Parameters: {"project_id"=>"test", "commit"=>"作成", "action"=>"new",
"controller"=>"issues", "custom_fields"=>{"7"=>"", "8"=>"", "13"=>"",
"14"=>"", "15"=>"foo...@ml.foobar.com"},
"issue"=>{"start_date"=>"2008-08-18", "estimated_hours"=>"",
"priority_id"=>"4", "subject"=>"test", "description"=>"test",
"tracker_id"=>"1", "category_id"=>"", "done_ratio"=>"0",
"due_date"=>"", "assigned_to_id"=>"", "status_id"=>"1"},
"attachments"=>{"1"=>{"description"=>"", "file"=>""}}}
Redirected to http://xxxxxx.xxxx.xxxx.xx/redmine/demo/projects/test/issues/show?id=44
Completed in 0.55051 (1 reqs/sec) | DB: 0.00000 (0%) | 302 Found
[http://xxxxxx.xxxx.xxxx.xx/redmine/demo/projects/test/issues/new]


Processing IssuesController#show (for xxx.xxx.xxx.xx at 2008-08-18
14:36:03) [GET]
Session ID: d8a35d6f5e821698f9c4593b56237443
Parameters: {"project_id"=>"test", "action"=>"show", "id"=>"44",
"controller"=>"issues"}
Rendering template within layouts/base
Rendering issues/show.rhtml
Completed in 0.13310 (7 reqs/sec) | Rendering: 0.09013 (67%) | DB:
0.00000 (0%) | 200 OK [http://xxxxxx.xxxx.xxxx.xx/redmine/demo/
projects/test/issues/show?id=44]
$
--- ここまで


fmkt

unread,
Aug 18, 2008, 7:58:10 AM8/18/08
to Redmine Users (japanese)
すみません...

少し間違えてましたかもしれません。

CustomValue.find(:all,:conditions => ["customized_type =
'Project'"],:select=>:value)
これでProjectのカスタムフィールドに設定されたカスタムバリューがすべて取れると思うのでご確認ください。

CustomField.find(:all) も試してください。
conditionsも入れると良いかもしれません。

> pp CustomField.find(:all,:conditions => ["name='Mailing list'"])
[#<ProjectCustomField id: 1, type: "ProjectCustomField", name:
"Mailing list", field_format: "string", possible_values: [], regexp:
"hogehoge", min_length: 0, max_length: 0, is_required: true,
is_for_all: false, is_filter: false, position: 1, searchable: false,
default_value: nil>]

ちなみに
> >> Project.find(:all).custom_values.find(:all)
> NoMethodError: undefined method `custom_values' for #<Array:
0xb6eea974>
このエラーは正しいです。
Project.find(:all)の結果はArrayで帰ってくるのでArrayに対してcustom_values を行おうとしていますが
そんなメソッドは存在しませんよってエラーですね。

やるならこうでしょうか。
Project.find(:all).map{|project| project.custom_values.find(:all)}

では。

taken

unread,
Aug 20, 2008, 7:00:53 AM8/20/08
to Redmine Users (japanese)
fmkt さん、コメントありがとうございます。

指示に従い、確認してみました。やはり挙動が怪しげな気が・・・。

$ sudo RAILS_ENV=production ruby ./script/console
Loading production environment (Rails 2.0.2)
>> >> CustomValue.find(:all,:conditions => ["customized_type = 'Project'"],:select=>:value)
=> []
>> >> CustomField.find(:all)
=> [#<IssueCustomField id: 7, type: "IssueCustomField", name: "CVS
version and files", field_format: "string", possible_values: [],
regexp: "", min_length: 0, max_length: 0, is_required: false,
is_for_all: true, is_filter: true, position: 3, searchable: true,
default_value: "">, #<IssueCustomField id: 8, type:
"IssueCustomField", name: "再現方法", field_format: "text",
possible_values: [], regexp: "", min_length: 0, max_length: 0,
is_required: false, is_for_all: true, is_filter: true, position: 4,
searchable: true, default_value: "">, #<IssueCustomField id: 13, type:
"IssueCustomField", name: "確認者", field_format: "string",
possible_values: [], regexp: "", min_length: 0, max_length: 0,
is_required: false, is_for_all: true, is_filter: false, position: 1,
searchable: false, default_value: "">, #<IssueCustomField id: 14,
type: "IssueCustomField", name: "最終確認者", field_format: "string",
possible_values: [], regexp: "", min_length: 0, max_length: 0, is_req
uired: false, is_for_all: true, is_filter: false, position: 2,
searchable: false, default_value: "">, #<IssueCustomField id: 15,
type: "IssueCustomField", name: "Mailing list", field_format:
"string", possible_values: [], regexp: "", min_length: 0, max_length:
0, is_required: false, is_for_all: false, is_filter: false, position:
5, searchable: false, default_value: "">]
>> >> CustomField.find(:all,:conditions => ["id = 15"])
=> [#<IssueCustomField id: 15, type: "IssueCustomField", name:
"Mailing list", field_format: "string", possible_values: [], regexp:
"", min_length: 0, max_length: 0, is_required: false, is_for_all:
false, is_filter: false, position: 5, searchable: false,
default_value: "">]
>> >> Project.find(:all).map{|project| project.custom_values.find(:all)}
=> [[], [], [], [], []]
>> >> quit
$

fmkt

unread,
Aug 20, 2008, 7:25:29 AM8/20/08
to Redmine Users (japanese)
こんにちは。

見た感じ、
> #<IssueCustomField id: 15, type: "IssueCustomField", name: "Mailing list", field_format: "string"...

"Mailing list", の設定は Issue(チケット) のカスタムフィールドで設定されてるのではないでしょうか?
こちらの認識が間違ってるかもしれませんが確認お願い致します。

もし、意図してIssueのに追加していた場合は、
CustomValue.find(:all,:conditions => ["customized_type =
'Issue'"],:select=>:value)
これでIssueごとに設定されたメールアドレスが表示されると思います。

で、この場合、app/models/project.rb に mailing_listメソッドを追加するのではなく、
app/models/issue.rb に追加しなくては取れないと思います。

では。

taken

unread,
Aug 21, 2008, 8:01:39 AM8/21/08
to Redmine Users (japanese)
fmkt さん

おかげさまで、解決しました。アドバイスありがとうございます m(__)m

> "Mailing list", の設定は Issue(チケット) のカスタムフィールドで設定されてるのではないでしょうか?

そのとおりです!!

> で、この場合、app/models/project.rb に mailing_listメソッドを追加するのではなく、
> app/models/issue.rb に追加しなくては取れないと思います。

ご指摘のとおりでした。以下のブログ・・・

http://fmkt.dip.jp/cgi-bin/bloq/blog.cgi?n=348&category=009

・・・にたいして、以下のように変更を加えて、動作するようになりました。

1. app/models/project.rb ではなく app/models/issue.rb に以下のメソッドを追加。

def mailing_list
if cv = custom_values.find(:first, :include => :custom_field,
:conditions => ["custom_fields.name = ?", "Mailing list"])
cv.value
end
end

2. app/models/mailer.rb の issue_add, issue_edit の修正を
issue.project.mailing_list でなく issue.mailing_list にする。

ocma

unread,
Aug 23, 2008, 1:14:17 AM8/23/08
to redmine-...@googlegroups.com
こんにちは。

アドレスで一目瞭然というか、そのブログを書いてる張本人ですが、
無事解決できたようでよかったです。

ついでにissueのカスタムフィールドに追加した場合の事としてここへのリンクを追記しておきます。

では。

Reply all
Reply to author
Forward
0 new messages