ruby on rails - Unknown column error with has_one association and join in named scope -
i have product , payment_notification model following association
class product < activerecord::base   has_one :payment_notification end  class paymentnotification < activerecord::base   belongs_to :product end i'm setting named scope should fetch products associated payment_notification has status completed.
i under impression should work in product model:
scope :completed, joins(:payment_notification).where(:payment_notification => { :status => 'completed' }) but results in following error:
error: mysql::error: unknown column 'payment_notification.status' in 'where clause': select     `products`.*       `items`  inner join `payment_notifications` on `payment_notifications`.`product_id` = `productss`.`id`     (`payment_notification`.`status` = 'completed') can help?
try this:
scope :completed, joins(:payment_notification).where(:payment_notifications =>                      { :status => 'completed' }) notice plural : payment_notifications.
Comments
Post a Comment