0

I have domain like

class Book {
    Author author
    String title
}

and another

class ListingTracking {
    Book book
    String oldVal
    String newVal
    Date modDate
    static constraints = {
    }
}

and now I need all those listingTacking which have a list of book ids but my criteria is on Book domain and I can not change association.

I tried

   def books= Book.createCriteria().list {

    'in'("id", [7,2,3,6].collect {it as Long} )
    createAlias("listingTracking","lt")
    projections{
        property("title")
    }
    'in'("lt.book.id",[7,2,3,6].collect {it as Long})

}

I know that I can't create createAlias of listingTracking in Book domain but I need something like that, Is this possible via criteria?.

ABC
  • 4,263
  • 10
  • 45
  • 72

1 Answers1

0
def listingTracking = ListingTracking.findAllByBookInList( Book.getAll([7,2,3,6]) )

Instead of Book.getAll you can use any finder you prefer on Books

Fabiano Taioli
  • 5,270
  • 1
  • 35
  • 49