45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/reactive_record/first_last_limits.rb', line 45
def find(*args)
options = args.
if @reflection.options[:finder_sql]
expects_array = args.first.kind_of?(Array)
ids = args.flatten.compact.uniq.map { |arg| arg.to_i }
if ids.size == 1
id = ids.first
record = load_target.detect { |r| id == r.id }
expects_array ? [ record ] : record
else
load_target.select { |r| ids.include?(r.id) }
end
else
merge_options_from_reflection!(options)
construct_find_options!(options)
find_scope = construct_scope[:find].slice(:conditions, :order)
with_scope(:find => find_scope) do
relation = @reflection.klass.send(:construct_finder_arel, options, @reflection.klass.send(:current_scoped_methods))
case args.first
when :first, :last
relation.send(*args)
when :all
records = relation.all
@reflection.options[:uniq] ? uniq(records) : records
else
relation.find(*args)
end
end
end
end
|