AdiFatLady
AdiFatLady

Reputation: 368

GORM/Grails - add extra column to a joinTable expression

I have a Domain Class setup similar to this

class NewsStory {
  String headline
  static hasMany = [channels:Channel]
  static mapping = {
      table 'NewsStory'
      addresses joinTable:[name:'Article_Channel', key:'ArticleId', column:'ChannelId']
  }
}

in the Article_Channel table i need to have an extra column populated called ArticleType say. Its value will always be the same e.g. 'news' for this domain class, but will be differnt for others e.g. 'blog' Channel is just something like 'Security' etc

Is there a way? Thanks

Upvotes: 2

Views: 3762

Answers (1)

schmolly159
schmolly159

Reputation: 3881

One option would be be to create your own many-to-many mapping class and add the field in there.

http://grails.org/Many-to-Many+Mapping+without+Hibernate+XML

So, for example:

class ArticleChannel {
    NewsStory newsStory
    Channel channel
    String articleType
}

Then, your NewsStory and Channel classes would hasMany the ArticleChannel class.

Upvotes: 3

Related Questions