Hi everyone (my first post!),
I have an HQL question (in Groovy/Grails) I was hoping someone could help me with.
I have a simple Asset object with a one-to-many Tags collection.
class Asset {
Set tags
static hasMany = [tags:Tag]
}
class Tag {
String name
}
What I'm trying to do in HQL:
A user passes in some tags in params.tags
(ex: groovy grails rocks) and wants to return Asset(s) that have those tags, and only those exact tags.
Here's my HQL that returns Assets if one or more of the tags are present in an Assets tags:
SELECT DISTINCT a
FROM
Asset a
LEFT JOIN
a.tags t
WHERE
t.name IN (:tags)
assetList = Asset.executeQuery( hql, [tags:tokenizedTagListFromParams]
The above code works perfect, but its really like an OR
. If any of the tag(s) are found, it will return that Asset.
I only want to return Assets that have those exact same tags (in number as well).
Every time a new tag is created, I new Tag(name:xxx).save()
so I can get the Tag instances and unique ID's for each tag that was asked for.
I also tried converting the passed in tags to a list of Tag instances with Tag.findByName(t1)
for each tag, and also a list of (unique) Tag Id's into the HQL above with no luck.
I would appreciate any help/advice.
Thank you for your time, Burt