Method: MongoDoc::ReferencesMany#references_many
- Defined in:
- lib/mongo_doc/references_many.rb
#references_many(*args) ⇒ Object
Declare reference to an array of Documents. The references can be ObjectId references or a BSON::DBRef, but cannot be both.
Use an ObjectId reference when you have a simple reference or will be referencing a single polymorphic collection. Example:
references_many :addresses references_many :addresses, :as => :work_address+
- classname
-
name of
Documenttype as anunderscoresymbol or string
- options
-
:asspecifies the name of the attribute, defaults to
classname
Use a BSON::DBRef when you need a reference to multiple collections. Example:
references_many :as_ref => :work_address
- required
-
:as_refname of the attribute
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/mongo_doc/references_many.rb', line 69 def references_many(*args) = args. if .has_key?(:as_ref) references_many_by_dbref([:as_ref].to_s) else klass = args[0].to_s.singularize.camelize references_many_by_id(klass, [:as].try(:to_s) || klass.demodulize.underscore.pluralize) end end |