I got into a doubt about Many-to-Many relationships and I hope I'm not asking a repeat question, but I did not find the solution to my question in the least.
It turns out that I have an image table, a job table, and a relationship table that makes a Many-to-Many relationship between the first two.
Each job can have several images related to it. So I did a query as follows:
select jobs.*, f1.file_name, f2.file_name
from jobs
left JOIN photos_per_job p ON p.job_id = jobs.id
left JOIN fotos f1 on p.photo_id = f1.id
inner join fotos f2 on jobs.foto_capa = f2.id
And I got the result below:
My problem now is to organize this information in the view. If you notice the work that has three photos repeats in the result three times, but when I show the works to the user I will show one job at a time and each job will have its series of photos.
Is there a way to organize the result in a way that facilitates my loop in the view or to organize this better do I need to work on the loop itself?