scala 中的多对多关系

发布于 2024-11-15 18:24:10 字数 507 浏览 6 评论 0原文

我的问题很简单。

我必须对具有多对多关系的类进行建模。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪化雨蝶 2024-11-22 18:24:11

由于您可能正在使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文