n0tttrui's avatar

Movies have many categories

How can I make the Eloquent a system of categories for films in which the film has more than one category?

0 likes
3 replies
gereini's avatar

The reason your query doesn't work is because each row has only one category. Instead, you need to do aggregation. I prefer doing the conditions in the having clause, because it is a general approach.

SELECT Name 
FROM categorytable
group by Name
having sum(case when category ='Action' then 1 else 0 end) > 0 and
       sum(case when category ='Sci-Fi' then 1 else 0 end) > 0;

Each clause in the having is testing for the presence of one category. If, for instance, you changed the question to be "Action films that are not Sci-Fi", then you would change the having clause by making the second condition equal to 0: same is used on Typhoon TV.

having sum(case when category ='Action' then 1 else 0 end) > 0 and
       sum(case when category ='Sci-Fi' then 1 else 0 end) = 0;
jhondikka's avatar

yeah. I've seen that class. However, it is merely about ingesting that external api of videos and rendering in pages. However, my project differs slightly in that I have a table to save movie details and upload the movie, but I want to collect the casts of that uploaded movie.

Please or to participate in this conversation.