Skip to content

Instantly share code, notes, and snippets.

@TakuyaHarayama
Last active June 7, 2017 16:18
Show Gist options
  • Save TakuyaHarayama/09ed4e5a7ac92db0de4d05b32b250a5e to your computer and use it in GitHub Desktop.
Save TakuyaHarayama/09ed4e5a7ac92db0de4d05b32b250a5e to your computer and use it in GitHub Desktop.
ユーザーと映画とユーザーのお気に入り映画があって、特定のユーザーのお気に入りの映画と邦画を合わせて取得するscope
scope :search_with_japanese_favorite_movie, -> (user_id) {
eager_load(:user_favorite_movies)
.merge( UserFavoriteMovie.where(user_id: user_id) )
.or( Movie.eager_load(:user_favorite_movies).where(made_in: "Japan") )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment