简体   繁体   English

单向1:M关系默认情况下使用联接表

[英]Unidirectional 1:M relationship uses join table by default

In Grails, a UniDirectional 1:M relationship uses a join table by default. 在Grails中,默认情况下,UniDirectional 1:M关系使用联接表。 See: http://grails.org/doc/2.3.7/guide/GORM.html#oneToMany 请参阅: http : //grails.org/doc/2.3.7/guide/GORM.html#oneToMany

Why is this? 为什么是这样?

And is there anyway to stop this behaviour. 而且有阻止这种行为的方法。

Thanks 谢谢

To avoid the join table in unidirectional 1:M, foreign key has to be specified in the parent for the associations: 为了避免单向1:M中的联接表,必须在父级中为关联指定外键:

class Book {

    static hasMany = [authors: Author]

    static mapping = {
        authors column: 'BOOK_AUTHOR_ID'
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM