gpt4 book ai didi

grails - Grails “Cannot set readonly property”

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

我有2个与多对多关系的域,并且这个关系的中间表

class Song implements Taggable {

static belongsTo = [User]

static hasMany = [audios: Audio, couplets: Couplet, hasSongListSong: HasSongListSong, hasSublistSong: HasSublistSong]

String title
Boolean isChorusRepeat = false
Boolean deleted = false
Date dateCreated, lastUpdated

static constraints = {
title blank: false, size:1..129
}
}

class SongList {

static belongsTo = [User]
static hasMany = [hasAccess: HasAccess, songListHasSong: HasSongListSong, songSubList: SongSubList]

String title
User user
Boolean deleted = false
Date dateCreated, lastUpdated

static constraints = {
title size: 3..128, blank: false, unique: false
}
}

带有Song和SongList id的中间表,用于存储关系
class HasSongListSong {

static belongsTo = [SongList, Song]

SongList songList
Song song

static constraints = {
}
}

当我尝试在此表中设置数据时,我得到了这个惊喜
def addSongs() {
def hasSong = new HasSongListSong();
hasSong.songId = Song.load(1)
hasSong.songListId = SongList.load(1)
}

第二个问题,如果我从前端范围的id接收到,如何更好地保存这种情况,我的意思是要向 Controller 发出带有songId 1,2,.. n集合的请求。我应该使用一些迭代器,或者有更好的方法?

最佳答案

您不设置ID,而是设置对象:

def addSongs() {
def hasSong = new HasSongListSong();
hasSong.song = Song.load(1)
hasSong.songList = SongList.load(1)
}

在第二个问题中问您一个新问题,我可以尝试回答。

关于grails - Grails “Cannot set readonly property”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29613393/

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