Class: Restorm::Model::Associations::Association
- Inherits:
-
Object
- Object
- Restorm::Model::Associations::Association
- Defined in:
- lib/restorm/model/associations/association.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#find(id) ⇒ Object
Fetches the data specified by id.
-
#reload ⇒ Object
Refetches the association and puts the proxy back in its initial state, which is unloaded.
-
#where(params = {}) ⇒ Object
(also: #all)
Add query parameters to the HTTP request performed to fetch the data.
Instance Method Details
#find(id) ⇒ Object
Fetches the data specified by id
97 98 99 100 101 |
# File 'lib/restorm/model/associations/association.rb', line 97 def find(id) return nil if id.blank? path = build_association_path -> { "#{@parent.request_path(@params)}#{@opts[:path]}/#{id}" } @klass.get_resource(path, @params) end |
#reload ⇒ Object
Refetches the association and puts the proxy back in its initial state, which is unloaded. Cached associations are cleared.
121 122 123 124 |
# File 'lib/restorm/model/associations/association.rb', line 121 def reload reset fetch end |
#where(params = {}) ⇒ Object Also known as: all
Add query parameters to the HTTP request performed to fetch the data
81 82 83 84 |
# File 'lib/restorm/model/associations/association.rb', line 81 def where(params = {}) return self if params.blank? && @parent.attributes[@name].blank? AssociationProxy.new clone.tap { |a| a.params = a.params.merge(params) } end |