Q:

Grails "Cannot set readonly property"

I have 2 domains with relation many to many, and middle table for this relation
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
    }
}

middle table with Song and SongList id for storing relation
class HasSongListSong {

    static belongsTo = [SongList, Song]

    SongList songList
    Song song

    static constraints = {
    }
}

When I try set data in this table I got this exceprion
def addSongs() {
    def hasSong = new HasSongListSong();
    hasSong.songId = Song.load(1)
    hasSong.songListId = SongList.load(1)
}

and second question if I receive from front-end scope of id, how better save it this case, I mean to controller come request with collection of songId 1,2,..n I should use some iterator or there is some more better way?

A:

You don't set the id's, you set the objects:
def addSongs() {
    def hasSong = new HasSongListSong();
    hasSong.song = Song.load(1)
    hasSong.songList = SongList.load(1)
}

Ask you second question in as a new Question and I can try and answer that.

