Hi, I might need a little help to figure out how I should follow as follows:
For information only, I work with the platform play 2.0 and version Ebeans ~ 2.7
I have model projects and model reports. A project can have many reports, but a report can only belong to one project.
This is my project model:
@Entity @Table(name = "Projects") public class Projects extends Model { private static final long serialVersionUID = -3343133304437498550L; @Id public long id; @NotNull @Size(min = 1, max = 255) public String name; @NotNull @Size(min = 1, max = 255) public String description; @Formats.DateTime(pattern = "dd/MM/yyyy") public Date created_at = new Date(); public static Finder<Long, Projects> find = new Finder<Long, Projects>(Long.class, Projects.class);
}
And this is my report model:
@Entity @Table(name = "Reports") public class Reports extends Model { private static final long serialVersionUID = -6617128169471038678L; @Id public long id; @Constraints.Required public String description; @Formats.DateTime(pattern = "dd/MM/yyyy") public Date created_at = new Date(); @ManyToOne @NotNull public Projects project; public static Finder<Long, Reports> find = new Finder<Long, Reports>(Long.class, Reports.class); }
Saving works without problems, I can create a project, and I can create several reports that indicate the correct projects. My question knows how I can address this question.
When I have a project, how can I get all reports related to it? I think I could understand this as a simple SQL query, but I'm sure this is possible with ebean.
Best wishes and thank you for your time!
UPDATE: This is how I would do it with an SQL query
SELECT * FROM `Projects` LEFT JOIN `Reports` ON Projects.`id` = Reports.`id`;