Take the 2-minute tour ×

Grails begginer question. I want to get all requests that fall in specific contact responsibility . How to do that using dynamic finders and how using? This would greatly help me understand GORM so thanks in advance. These are my domain classes.

EDIT: To clarify my problem, Request instance has productline which is instance of Productline domain class (and there is Productline productline in my Request domain class). Responsibility (domain class) is basicaly just pairs of productlines and contacts. When I create contact I also define its responsibilities. So each Contact can be responsible for many Productlines. For Example, John Doe is Contact. Productlines are Cars, Trucks, Airplanes, Trains. And Responsibilities (for John Doe) are: [John Doe, Trucks], [John Doe, Cars]. I want to get all Requests that fall in the responsibilities of John Doe. So what I need is to get productlines from responsibilities where contact is John Doe. And then get all Requests that have those productlines.


class Contact {

   String realname
   String company
   String mobile
   String fix
   String email
   User user

   String toString() {

   static hasMany = [responsibilities: Responsibility]

   List productlines() {
      return responsibilities.collect{it.productline}

   List addToProductline(Productline productline) {
      Responsibility.link(this, productline)
      return productline()

   List removeFromProductline(Productline productline){
      Responsibility.unlink(this, productline)
      return productline()


class Productline {

   String productline

   String toString() {

   static hasMany = [topics: Topic]

   List contacts() {
      return responsibilities.collect{it.contact}

   List addToContacts(Contact contact) {
      Responsibility.link(contacts, this)
      return contacts()

   List removeFromContacts(Contact contact){
      Responsibility.unlink(contact, this)
      return contacts()


class Responsibility {

   Contact contact
   Productline productline

   String toString(){
      "$contact " + "$productline"

   static Responsibility link(contact, productline) {
      def r = Responsibility.findByContactAndProductline(contact, productline)
      if (!r) {
         r = new Responsibility()
      return r

   static void unlink(contact, productline){
      def r = Responsibility.findByContactAndProductline(contact, productline)
      if (r) {

   static void removeAll(contact) {
      executeUpdate 'DELETE FROM Responsibility WHERE contact=:contact', [contact: contact]


class Request{   
   String requestID
   Date dateCreated
   String subject
   String startedBy 
   String description
   String status
   String priority 
   Productline productline
   Topic topic
   Subtopic subtopic
   String company
   String acceptedBy
   String suggestedSupport
   String requestType
   Date dateClosed
   int daysOpened
   byte[] picture1
   byte[] picture2
   byte[] picture3

   static constraints = {
      status (blank:true,nullable:true)
      priority(blank:true,nullable:true, inList:["Normal","Urgent","Not urgent"])
      picture1(blank:true,nullable:true, maxSize:5000000)
      picture2(blank:true,nullable:true, maxSize:5000000)
      picture3(blank:true,nullable:true, maxSize:5000000)

   static mapping = {
      picture1 column:"picture1", sqlType: "longblob"
      picture2 column:"picture2", sqlType: "longblob"
      picture3 column:"picture3", sqlType: "longblob"
share|improve this question
"I want to get all requests..." - what's Request? There's nothing by that name in your domains. –  Rob Hruska Dec 29 '11 at 14:05
@RobHruska Sorry. My mistake. I've edited my question. –  drago Dec 29 '11 at 14:15
@RobHruska Also, it would be great if you could recommend me some resources for learning GORM. –  drago Dec 29 '11 at 14:29
As far as resources go, Chapter 5 of the documentation has all of the basics. Other than that, maybe look at the GORM questions on SO. –  Rob Hruska Dec 29 '11 at 14:39
add comment


Your Answer



Browse other questions tagged or ask your own question.