class Company < ActiveRecord::Base has_many :licenses def filter_licenses_using(search_filters) result = self.licenses search_filters.each { |key, value| result = result.public_send(key, value) if value.present? } result end end