Method: Mongoid::Relations::Accessors::ClassMethods#ids_setter

Defined in:
lib/mongoid/relations/accessors.rb

#ids_setter(name, metadata) ⇒ Object

Defines the setter method that allows you to set documents in this relation by their ids. The defined setter, finds documents with given ids and invokes regular relation setter with found documents. Ids setters should be defined only for referenced many relations.

@param [ String, Symbol ] name The name of the relation.
@param [  ]  The  for the relation.

@return [ Class ] The class being set up.

Examples:

Set up the id_setter for the relation.

Person.ids_setter("addesses", )


289
290
291
292
293
294
295
# File 'lib/mongoid/relations/accessors.rb', line 289

def ids_setter(name, )
  ids_method = "#{name.to_s.singularize}_ids="
  re_define_method(ids_method) do |ids|
    send(.setter, .klass.find(ids.reject(&:blank?)))
  end
  self
end