1

Are there advanced uses for Grails command objects? Majority of the pages out there have a command object with all of its fields as Strings, Floats, Integers. Is there a way to make it use domain classes similar to how a Domain class may have have a reference to another domain class.

Jay Prall
  • 5,295
  • 5
  • 49
  • 79
Christian
  • 1,241
  • 2
  • 8
  • 11

2 Answers2

1

I don't see why not. Sure they can hold instances to other domain classes. Typically command objects are used when you only need a subset of the properties of your domain class or when there is no corresponding domain class.

aldrin
  • 4,482
  • 1
  • 33
  • 50
1

Yes, this is completely legal, and I use them this way in projects all the time. Their purpose is to validate input, and the main difference between a domain object and a command object is that the command object is not persisted.

Most of the sites probably do not use other Objects in order to make the example a bit simpler to understand.

Igor
  • 33,276
  • 14
  • 79
  • 112