lib/active_remote/association.rb in active_remote-2.4.0 vs lib/active_remote/association.rb in active_remote-3.0.0.pre1

- old
+ new

@@ -81,10 +81,13 @@ search_hash[foreign_key] = object.guid search_hash[options[:scope]] = object.read_attribute(options[:scope]) if options.has_key?(:scope) search_hash.values.any?(&:nil?) ? [] : klass.search(search_hash) end + + options.merge!(:has_many => true) + create_setter_method(has_many_class, options) end # Create a `has_one` association for a given remote resource. # Specify one or more associations to define. The constantized # class must be loaded into memory already. A method will be defined @@ -133,9 +136,10 @@ private def create_setter_method(associated_klass, options={}) writer_method = "#{associated_klass}=".to_sym define_method(writer_method) do |new_value| + raise "New value must be an array" if options[:has_many] == true && new_value.class != Array klass_name = options.fetch(:class_name){ associated_klass } klass = klass_name.to_s.classify.constantize instance_variable_set(:"@#{new_value.class.name.demodulize.underscore}", new_value) new_value