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