gpt4 book ai didi

grails - Groovy Grails多对多关联创建2个连接表

转载 作者:行者123 更新时间:2023-12-02 15:14:00 25 4
gpt4 key购买 nike

因此,我有2个类(class)具有许多关联。生成数据库后,我得到2个联接表:user_link_sections和link_section_users。我期望的第一个,但不确定为什么生成第二个联接表。 Grails也只使用第一个。我不喜欢groovy / grails,但是尝试按照文档进行设置。任何帮助表示赞赏!

这是我的域类声明...

class User {

transient springSecurityService

// Custom Attributes
String firstName
String lastName
String email
String company
String phone
Date dateCreated
Date lastUpdated

static hasMany = [linkSections: LinkSection]

String username
String password
boolean enabled
boolean accountExpired
boolean accountLocked
boolean passwordExpired
}


class LinkSection {

String name
String description
Date dateCreated
Date lastUpdated

List links = new ArrayList()

static belongsTo = User
static hasMany = [links: Link, users: User]

static constraints = {
name blank: false
description(maxSize: 10000)
}

static mapping = {
links cascade: "all,delete-orphan"
}
}

最佳答案

尝试设置多方所有权:

static belongsTo = User

这在LinkSection上进行。记住只有一方知道要保持这种关系。

要做的另一件事是确保并清除以前尝试映射时可能遗留下来的表...只是为了确保。

关于grails - Groovy Grails多对多关联创建2个连接表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7904472/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com