@@ -1,51 +1,52 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2012 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | module ActiveRecord |
|
18 | module ActiveRecord | |
19 | module FinderMethods |
|
19 | module FinderMethods | |
20 | def find_ids(*args) |
|
20 | def find_ids(*args) | |
21 | find_ids_with_associations |
|
21 | find_ids_with_associations | |
22 | end |
|
22 | end | |
23 |
|
23 | |||
24 | private |
|
24 | private | |
25 |
|
25 | |||
26 | def find_ids_with_associations |
|
26 | def find_ids_with_associations | |
27 | join_dependency = construct_join_dependency_for_association_find |
|
27 | join_dependency = construct_join_dependency_for_association_find | |
28 | relation = construct_relation_for_association_find_ids(join_dependency) |
|
28 | relation = construct_relation_for_association_find_ids(join_dependency) | |
29 | rows = connection.select_all(relation, 'SQL', relation.bind_values) |
|
29 | rows = connection.select_all(relation, 'SQL', relation.bind_values) | |
30 | rows.map {|row| row["id"].to_i} |
|
30 | rows.map {|row| row["id"].to_i} | |
31 | rescue ThrowResult |
|
31 | rescue ThrowResult | |
32 | [] |
|
32 | [] | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | def construct_relation_for_association_find_ids(join_dependency) |
|
35 | def construct_relation_for_association_find_ids(join_dependency) | |
36 | relation = except(:includes, :eager_load, :preload, :select).select("#{table_name}.id") |
|
36 | relation = except(:includes, :eager_load, :preload, :select).select("#{table_name}.id") | |
37 | apply_join_dependency(relation, join_dependency) |
|
37 | apply_join_dependency(relation, join_dependency) | |
38 | end |
|
38 | end | |
39 | end |
|
39 | end | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | class DateValidator < ActiveModel::EachValidator |
|
42 | class DateValidator < ActiveModel::EachValidator | |
43 | def validate_each(record, attribute, value) |
|
43 | def validate_each(record, attribute, value) | |
44 | before_type_cast = record.attributes_before_type_cast[attribute.to_s] |
|
44 | before_type_cast = record.attributes_before_type_cast[attribute.to_s] | |
45 | if before_type_cast.is_a?(String) && before_type_cast.present? |
|
45 | if before_type_cast.is_a?(String) && before_type_cast.present? | |
46 | unless before_type_cast =~ /\A\d{4}-\d{2}-\d{2}\z/ && value |
|
46 | # TODO: #*_date_before_type_cast returns a Mysql::Time with ruby1.8+mysql gem | |
|
47 | unless before_type_cast =~ /\A\d{4}-\d{2}-\d{2}( 00:00:00)?\z/ && value | |||
47 | record.errors.add attribute, :not_a_date |
|
48 | record.errors.add attribute, :not_a_date | |
48 | end |
|
49 | end | |
49 | end |
|
50 | end | |
50 | end |
|
51 | end | |
51 | end |
|
52 | end |
General Comments 0
You need to be logged in to leave comments.
Login now