This plugin adds support for favourites. Mark up any of your domain classes as having favourites.
grails install-plugin favourite
Assume you have a product domain for which you want to add favorite feature.
Implement the AddToFavourites interface:
Product.groovy
import grails.plugin.favourites.AddToFavourites
class Product implements AddToFavourites{
String name
}
User.groovy
import grails.plugin.favourites.AddToFavourites
class User implements AddToFavourites{
}
Add a particular product to user favorite list
def product = Product.get(1)
def user = User.get(1)
product.addToFavouritesOf(user)
Remove product from user favourites
product.removeFromFavouritesOf(user)
Get all user favourites
user.favourites.each{
println it.favourite.name
}
Note:-
it.favourite
will be the instance of object that you have added in favourite, so in above case it is object of first product so you can access all attributes of product likeit.favourite.name