NutzCN Logo
问答 @ManyMany已经不够用了,有没有@ManyManyMany
发布于 2920天前 作者 xiciliu 2537 次浏览 复制 上一个帖子 下一个帖子
标签:

刚才白写了。
Book{id,name,isbn}
Author{id,name}
BookAuthor{id,bookid,authorid,type} //type: 0, 作者; 1,译者
@ManyMany已经不够用了,有没有@ManyManyMany呢?

11 回复

你在说神马??

哈哈
2个类book,author。
在book中创建
@ManyMany(from = "bookid", relation = "BookAuthor", target = Author.class, to = "authorid")
List authors //此种情况,BookAuthor->type=0
以及
@ManyMany(from = "bookid", relation = "BookAuthor", target = Author.class, to = "authorid")
List translators //此种情况,BookAuthor->type=0
不能在ManyMany注解中指明type。
所以authors和translators是一样的了。

@xiciliu(xiciliu)
List translators //此种情况,BookAuthor->type=0 这里应改为 type=1

@ManyMany(from = "bookid", relation = "BookAuthor", target = Author.class, to = "authorid")
	private List<Author> authors;//此种情况,BookAuthor->type=0
	
	@ManyMany(from = "bookid", relation = "BookAuthor", target = Author.class, to = "authorid")
	private List<Author> translators;//此种情况,BookAuthor->type=0 这里应改为 type=1

关联关系中需要多个列关联?

对的。
在表BookAuthor中,同一个bookid,还需要区分type列,才能找到目标authorid。

连Many都没用过。。。
从来都是单表操作,我好戳 

@xiciliu 暂时提供不了,报个issue吧

@xiciliu 我觉得还是业务设计的问题,正常的场景不会用到这么多关联

@qq_2a1c6850 解决方法当然是有的。只是想要nutz更强大。最重要的是为了偷懒,nutz越强大,我们就可以越懒了。

添加回复
请先登陆
回到顶部