This is a Groovy model and Controller?  Is this a grails app?

-D

On May 20, 2008, at 4:38 AM, Julien C. wrote:

Hi,

I have a class Annonce with an unidirectional one to many relation with class media. I use a SortedSet for this. It works when there is only 1 media but if I had an other media it fails silently. If I replace SortedSet with a simple Set it works correctly.
What is the problem in my code ?

class Annonce extends Produit {

    String titre
    SortedSet medias
    static hasMany = [ medias: Media ]

    static mapping = {
medias joinTable:[name:'annonce_media', key:'annonce_id', column:'media_id'], lazy:true
    }

}


class Media implements Comparable {

    String nom
    Integer ordre = 0

    ...

    int compareTo(obj) {
       return ordre.compareTo(obj.ordre);
    }

}

class MediaImage extends Media{

    int largeur
    int hauteur

}


// In the controller
def aMedia = new MediaImage()
...
annonce.addToMedias( aMedia )
if (annonce.save(flush: true)){
    ...
}


Thanks. Julien C.

Reply via email to