-2

I have a domaing named Thana where I save thanaName with the parent id of district. I have used unique constraint for thanaName. When I save thana with a name suppose 'Thana A' with the district foreign key value 1 it's saved. When I want to save the 'Thana A' again with district foreign key value 2 it would not save it because of unique constraint. But I need to do it cause here district are different although the thanaName are same. Can anyone please help me on this please ? Thanks a lot.

    class Thana {

    String thanaName
    District district

    static constraints = {
        thanaName unique: true // each instance must have a unique name.
    }

    static mapping = {
        table('thana')
        version(false)
        district column: 'district_id'
    }
}
Sumon Bappi
  • 1,937
  • 8
  • 38
  • 82

1 Answers1

0

You can use multi-column unique constraints, here is the link of the documentation:

Unique

Abincepto
  • 1,016
  • 8
  • 13