5

I have a domain class in grails... How do I get gorm to leave out this entity when it create the db? Just leave it alone.

user903772
  • 1,554
  • 5
  • 32
  • 55

3 Answers3

14

If i understood, u want not create table from domain class? If yes, use this code inside domain class:

static mapWith = "none" // disable persisting into database
jenk
  • 1,043
  • 7
  • 8
  • The other answers to this question are fine and helpful, but this one is strictly the correct answer to the question. – scrotty Jan 06 '13 at 00:30
  • 1
    And the default value for `mapWith` is `"GORM"`. See [the grails source](https://github.com/grails/grails-core/blob/31af2108f171534edca3f6f15391364ee1fb2641/grails-core/src/main/groovy/org/grails/core/DefaultGrailsDomainClass.java) – GreenGiant Aug 14 '14 at 22:53
9

Sounds like you don't need it to be a domain class then. You could just make it a POGO in the src/groovy file. If my assumptions here are wrong please explain further what you're trying to accomplish.

Jarred Olson
  • 3,075
  • 1
  • 19
  • 34
2

You could use Command Objects.

http://grails.org/doc/latest/guide/single.html#commandObjects

They provide the data binding and validation of domain classes, but do not map to the database.

Patrick
  • 2,102
  • 15
  • 11
  • 1
    You're taking advantage of a side-effect that command objects become validateable. It's better to create a src/groovy class and annotate it with `grails.validation.Validateable` – Burt Beckwith Jan 17 '12 at 22:00
  • The Grails documentation on Command Objects specifically notes the validation feature, so it doesn't look like they are treating it as a side-effect. – Patrick Jan 17 '12 at 23:26
  • 1
    You have to declare the command object in a controller to make it a command object. If you don't use it as a command object but just take advantage of its validation features as a non-persistent domain class, it's a side effect. – Burt Beckwith Jan 17 '12 at 23:44