Enum Queries with Joins and Associations
When working with associations, you can filter records based on enum values from related models.
Example: Suppose we have a Post
model belonging to a User
:
class Post < ApplicationRecord
belongs_to :user
end
Now, let's fetch all posts from active users:
Post.joins(:user).where(users: { status: :active })