Play框架加入并建立模型 [英] Play Framework joins and the model
本文介绍了Play框架加入并建立模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这不是问题,更多的是这是正确的方法"这类交易.
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;
}
现在,我要访问其B对象中所有具有特定c值的A对象.
Now I want to access all objects of A that have a particular value of c in their B objects.
所以我应该
- 获取具有特定值c的B的所有对象,然后找到与这些对象相对应的A(如果这样,则感到困惑)
- 使用
find.all()
获取A的所有对象,然后浏览列表(这似乎是一个坏主意,因为会有很多A,而没有那么多B).
- 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).
任何帮助将不胜感激(哦,假设我已经写了@Entity
和@Required
,并且其余所有都适当地写了)
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();
如果未自动获取,则可能添加fetch("b").
Possibly adding a fetch("b"), if it isn't fetched automatically.
这篇关于Play框架加入并建立模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文