Module: ElasticRecord::SearchesMany::ClassMethods
- Defined in:
- lib/elastic_record/searches_many.rb
Instance Method Summary collapse
- #generated_searches_many_methods ⇒ Object
-
#searches_many(name, options = {}) ⇒ Object
Specifies a one-to-many association.
Instance Method Details
#generated_searches_many_methods ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/elastic_record/searches_many.rb', line 61 def generated_searches_many_methods @generated_searches_many_methods ||= begin mod = const_set(:GeneratedSearchesManyMethods, Module.new) include mod mod end end |
#searches_many(name, options = {}) ⇒ Object
Specifies a one-to-many association. The following methods for retrieval and query of collections of associated objects will be added:
- collection
-
Returns an array of all the associated objects.
- collection=objects
-
Replaces the collections content by deleting and adding objects as appropriate.
- collection_params=objects
-
Support for nested assignment from a form
Options
- :as
-
Specifies a polymorphic interface (See
belongs_to
). - :touch
-
Specify to update the owner when changed. Specify
true
to update the updated_at field. If you specify a symbol, that attribute will be updated with the current time in addition to the updated_at/on attribute. - :autosave
-
If true, always save the associated objects or destroy them if marked for destruction, when saving the parent object.
- :counter_cache
-
Caches the number of belonging objects on the associate class. This requires that a column named
#{table_name}_count
(such ascomments_count
for a belonging Comment class) is used on the associate class (such as a Post class). You can also specify a custom counter cache column by providing a column name instead of atrue
/false
value to this option (e.g.,:counter_cache => :my_custom_counter
.) - :class_name
-
Specify the class name of the association. Use it only if that name can’t be inferred from the association name. So
has_one :manager
will by default be linked to the Manager class, but if the real class name is Person, you’ll have to specify it with this option.
Example
Example: A Firm class declares has_many :clients
, which will add:
-
Firm#clients
-
Firm#clients=(objects)
-
Firm#client_params=(params)
57 58 59 |
# File 'lib/elastic_record/searches_many.rb', line 57 def searches_many(name, = {}) ElasticRecord::SearchesMany::Builder.build(self, name, ) end |