Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a custom id column in GORM

I have a domain object that has a property that i want to be used as the id by GORM, the reason being is that ill be saving lists of this object and i want existing rows to be updated if the id already exists in the database

Lets assume that my property i want as the PK is called listId

Ive seen several approaches to this, which is best?

1:

id generator: 'identity', column: 'listId'

2:

  static mapping = {
    id generator:'assigned'
  }
  def getKey = {
    return listId;
  }

or something entirely different?

like image 207
mkoryak Avatar asked Dec 07 '10 19:12

mkoryak


1 Answers

  static mapping = {
    id generator: 'assigned', name: "listId", type: 'string'
  }
like image 74
Aaron Saunders Avatar answered Oct 14 '22 07:10

Aaron Saunders