lib/ripple/associations/many_reference_proxy.rb in ripple-1.0.0.beta vs lib/ripple/associations/many_reference_proxy.rb in ripple-1.0.0.beta2
- old
+ new
@@ -7,23 +7,24 @@
module Associations
class ManyReferenceProxy < Proxy
include Many
def <<(value)
- @reflection.verify_type!([value], @owner)
+ values = Array.wrap(value)
+ @reflection.verify_type!(values, @owner)
- assign_key(value)
+ values.each {|v| assign_key(v) }
load_target
- @target << value
+ @target.merge values
self
end
def replace(value)
@reflection.verify_type!(value, @owner)
delete_all
- Array(value).compact.each do |doc|
+ Array.wrap(value).compact.each do |doc|
assign_key(doc)
end
loaded
@keys = nil
@target = Set.new(value)
@@ -41,10 +42,11 @@
assign_key(value, nil)
@target.delete(value)
end
def target
+ load_target
@target.to_a
end
def keys
@keys ||= Ripple.client.search(klass.bucket_name, "#{key_name}: #{@owner.key}")["response"]["docs"].inject(Set.new) do |set, search_document|
@@ -88,6 +90,6 @@
target.update_attribute(key_name, key)
end
end
end
end
-end
\ No newline at end of file
+end