Tip in joins


If you need to query users which profile is validated you may end up doing:
# User model
scope :activated, ->{
  joins(:profile).where(profiles: { activated: true })
}
Instead this use this aproach


# Profile model
scope :activated, ->{ where(activated: true) }
# User model
scope :activated, ->{ joins(:profile).merge(Profile.activated) }

https://medium.com/@apneadiving

Comments