To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / lib / redmine / core_ext / active_record.rb @ 1568:bc47b68a9487
History | View | Annotate | Download (1.93 KB)
| 1 |
# Redmine - project management software
|
|---|---|
| 2 |
# Copyright (C) 2006-2014 Jean-Philippe Lang
|
| 3 |
#
|
| 4 |
# This program is free software; you can redistribute it and/or
|
| 5 |
# modify it under the terms of the GNU General Public License
|
| 6 |
# as published by the Free Software Foundation; either version 2
|
| 7 |
# of the License, or (at your option) any later version.
|
| 8 |
#
|
| 9 |
# This program is distributed in the hope that it will be useful,
|
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
# GNU General Public License for more details.
|
| 13 |
#
|
| 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
|
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
| 17 |
|
| 18 |
module ActiveRecord |
| 19 |
module FinderMethods |
| 20 |
def find_ids(*args) |
| 21 |
find_ids_with_associations |
| 22 |
end
|
| 23 |
|
| 24 |
private |
| 25 |
|
| 26 |
def find_ids_with_associations |
| 27 |
join_dependency = construct_join_dependency_for_association_find |
| 28 |
relation = construct_relation_for_association_find_ids(join_dependency) |
| 29 |
rows = connection.select_all(relation, 'SQL', relation.bind_values)
|
| 30 |
rows.map {|row| row["id"].to_i}
|
| 31 |
rescue ThrowResult |
| 32 |
[] |
| 33 |
end
|
| 34 |
|
| 35 |
def construct_relation_for_association_find_ids(join_dependency) |
| 36 |
relation = except(:includes, :eager_load, :preload, :select).select("#{table_name}.id") |
| 37 |
apply_join_dependency(relation, join_dependency) |
| 38 |
end
|
| 39 |
end
|
| 40 |
end
|
| 41 |
|
| 42 |
class DateValidator < ActiveModel::EachValidator |
| 43 |
def validate_each(record, attribute, value) |
| 44 |
before_type_cast = record.attributes_before_type_cast[attribute.to_s] |
| 45 |
if before_type_cast.is_a?(String) && before_type_cast.present? |
| 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 |
| 48 |
record.errors.add attribute, :not_a_date
|
| 49 |
end
|
| 50 |
end
|
| 51 |
end
|
| 52 |
end
|