dimanche 26 mars 2017

Rails get a has_one relation on a has_many relation

On a product/order and feedbacks relation how to find and relate the feedbacks to product?

Product Model
  has_many :orders
end

Order Model
  belongs_to :product
 belongs_to :feedback
end


Feedback Model
  has_one :order
end

I've tried get directly but how error someone have a hint?

Product Controller

def index
@total_feedbacks = Product.where(orders: Order.first).where('buyer_feedback_date is not null').count

@total_feedbacks = Feedback.joins(:products).where('products = ?', @products).where('buyer_feedback_date is not null').count

end
end

Aucun commentaire:

Enregistrer un commentaire