scala 中的多对多关系
我的问题很简单。
我必须对具有多对多关系的类进行建模。
case class A(
id: Pk[Long],
name: String
)
case class B(
id: Pk[Long],
name: String
)
在使用 java 时,由于 Hibernate 框架,您可以相当容易地编写此代码:
@ManyToMany(cascade=CascadeType.PERSIST)
public Set<A> allAs;
现在在使用 Scala 中添加这两个类之间的多对多关系的正确方法是什么?
我是否必须自己对辅助表进行建模,如下所示:
case class AToB(
a_id: Long,
b_id: Long
)
或者是否有更好、更简单的方法,无需辅助表的(不必要的)代码?
My question is fairly easy.
I have to model classes which are have a many-to-many relationship.
case class A(
id: Pk[Long],
name: String
)
case class B(
id: Pk[Long],
name: String
)
In play with java you can code this fairly easy, because of the Hibernate framework:
@ManyToMany(cascade=CascadeType.PERSIST)
public Set<A> allAs;
What is now the proper way in Play with Scala to add a many to many relationship between these two classes?
Do I have to model the helper table myself like this:
case class AToB(
a_id: Long,
b_id: Long
)
Or is there a better, easier way without the (unnecessary) code for the helper table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您可能正在使用 anorm,因此您必须使用 sql 的功能自己完成,因为 anorm 不是 orm
Since you are probably using anorm, you have to do it yourself using the powers of sql, since anorm is not an orm