41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/efo_nelfo/has_many.rb', line 41
def has_many(name, options)
post_type = options[:post_type]
@associations ||= {}
@associations[post_type] = name
define_method name do
instance_variable_get("@#{name}") || instance_variable_set("@#{name}", EfoNelfo::Collection.new(self, post_type))
end
define_method "#{name}=" do |values|
instance_variable_set "@#{name}", EfoNelfo::Collection.new(self, post_type)
values.each { |item| instance_variable_get("@#{name}") << item } if values
end
end
|