11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/activerecord-lazy.rb', line 11
def association_accessor_methods_with_lazy(reflection, association_proxy_class)
original = association_accessor_methods_without_lazy(reflection, association_proxy_class)
if reflection.options[:lazy]
constructor = reflection.options[:lazy].to_s
raise ActiveRecordError, 'has_one :lazy option must be :build or :create' unless %w[build create].include?(constructor)
define_method "#{reflection.name}_with_lazy" do
send("#{reflection.name}_without_lazy") || send("#{constructor}_#{reflection.name}")
end
alias_method_chain reflection.name, :lazy
end
original
end
|