Posted 15 days ago. Visible to the public. Linked content.

Minidusen: Filtering associated records

Minidusen lets you find text in associated records.

Assume the following model where a Contact record may be associated with a Group record:

Copy
class Contact < ApplicationRecord belongs_to :group validates_presence_of :name, :street, :city, :email end class Group < ApplicationRecord has_many :contacts validates_presence_of :name end

We can filter contacts by their group name by joining the groups table and filtering on a joined column.
Note how the joined column is qualified as groups.name (rather than just name):

Copy
class ContactFilter include Minidusen::Filter filter :text do |scope, phrases| columns = [:name, :email, 'groups.name'] scope.includes(:group).where_like(columns => phrases) end end

makandra has been working exclusively with Ruby on Rails since 2007. Our laser focus on a single technology has made us a leader in this space.

Owner of this card:

Avatar
Henning Koch
Last edit:
15 days ago
by Henning Koch
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more