问题
This isn't a problem, its more of a "is this the right approach" kind of deal.
So lets say I have a model like this
class A extends Model{
@OneToMany(cascade = CascadeType.ALL)
public B;
}
class B extends Model{
String c;
}
Now I want to access all objects of A that have a particular value of c in their B objects.
So should I:
- Get all objects of B with a certain value c and then find corresponding A's with those objects(if so how, getting confused)
- Get all objects of A with
find.all()
then look through the list (seems a bad idea as there will be a large amount of A's and not so many B's).
Any help would be appreciated (oh and assume I've written @Entity
and @Required
and all the rest appropriately)
回答1:
Option 1 is the right way to go. You can use a query such as
A.find().where().eq("b.id", yourBId).findList();
Possibly adding a fetch("b"), if it isn't fetched automatically.
来源:https://stackoverflow.com/questions/17449406/play-framework-joins-and-the-model