I have a join table called ProductFeatures
which joins Product
and Feature
instances via has_many: ..., through: product_features
, and has an additional column called rating
.
I want to add .rating
method on Feature
which will return a rating float based on specific product instance that is calling it. Something like:
Product.find(...).features.first.rating #=> should specific product_feature rating
I've tried:
- passing caller_id as an argument to
.rating
. This works, but makes me use product.id each time I want to get a specific product rating feature. - Obtaining a caller instance id from inside the method using
.caller
(with binding_of_caller, or vanilla Ruby), but.caller
does not seem to let me get a calling instance id, and would also fail in tests as the caller would be the spec'sExampleGroup