I have an API in which i have a HABTM relationship between Characters and Movies (a movie has many characters and a character has many movies). I'm trying to set up a filter with has_scope gem so i can do something like
/api/characters?by_movie=:movie_id
so instead of getting all the Characters from index in my CharactersController, i only get the characters that take part in a specific movie.
The way the relationship is set up allows me to do something like Characters.find(1).movies
-> returns the list of movies of that character. And if i send a POST to character and i want to add movies to it i can do it like "movie_ids":[1,2].
I have tried this approach with no success:
in my Character.rb scope :by_movie, -> id, {where(movie_ids: id)}
and scope :by_movie, -> id, {where(movies: id)}
and in my controller: has_scope :by_movie, using: :id
The documentation in has_scope is very little, i wasn't able to find my specific problem, i hope some of you can help me, thank you.