Making a scope that uses scopes from its associations

Viewed 31

I want to know how to make a scope, that uses the scope of its associations. Let me give you an example. (I hope you do not find it contrived)

I have a model Wife and Husband. The husband has a scope that, based on several of his attributes, filters good husbands.

How could I build now a scope on Wife to filter all the wives that have good husbands?

class Wife
    #Sorry for how that sounds
    belongs_to :husband

    scope :with_good_husband, -> { ???? }
end

class Husband
    scope :good, -> { ...whatever... }
end
1 Answers
Related