0

I have in my domain class a set of Integers like...

class MyDomain {
    (...)
    Set ids
    (...)
}

And would like to have a criteria to find if my object has an specifid id in that set.

Which means something like...

MyDomain.withCriteria {
    /* ids contains myId * /
}

'in' doesn't work - I want the reverse. myId must be within ids.

So - anyone can help me with that?

edit:

Let's suppose I have a MyDomain object with an ids set containing [2,3] and another having [3,4].

I want to have a criteria that returns all MyDomain objects that contains the id 2 in the ids set, so the result value of my criteria would be a list containing only the first MyDomain object mentioned.

Bianca Rosa
  • 197
  • 1
  • 3
  • 10
  • 1
    Maybe this? http://stackoverflow.com/questions/11475009/is-there-a-contains-functionality-on-a-collection-property-of-a-domain-object –  Aug 16 '13 at 17:53
  • Can you give an example of the data and what would be returned vs ignored? Your verbal description of the query is a little vague. – codelark Aug 16 '13 at 20:55
  • @Sérgio - Actually this link was helpful, but not for that specific situation, since I have a Set of ids and not a set of an object that has an id... Turns out I can't use IdEq nor have a criteria like: `ids { idEq(myId) }` ... since the I have the ids itself in my set. – Bianca Rosa Aug 20 '13 at 17:35
  • @codelark I've edited the description - I'm not sure if it's clearer now, though. – Bianca Rosa Aug 20 '13 at 17:42

1 Answers1

0

Follow the link @Sergio posted if you want/need criteria, however I prefer HQL:

MyDomain.executeQuery("Select m from MyDomain m join m.ids as id where id = :id", [id: myId])
James Kleeh
  • 12,094
  • 5
  • 34
  • 61