Module: Fera::HasManyReviews
- Extended by:
- ActiveSupport::Concern
- Included in:
- Customer, Product, Submission
- Defined in:
- lib/fera/models/concerns/has_many_reviews.rb
Instance Method Summary collapse
Instance Method Details
#reviews(query = {}) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/fera/models/concerns/has_many_reviews.rb', line 22 def reviews(query = {}) if @reviews && query.blank? @reviews.to_a else Review.where(query.merge("#{ self.class.name.demodulize.underscore }_id" => id)) end end |
#reviews=(new_reviews) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/fera/models/concerns/has_many_reviews.rb', line 11 def reviews=(new_reviews) @reviews = new_reviews.to_a.map do |model| if model.is_a?(Review) model else model_id = model.try(:with_indifferent_access).try(:[], :id) Review.new(model, model_id.present?) end end end |