groovy - Grails find in relationship -


i'm breaking head wall logic, have 2 domains, user , rss. when user add rss, have compare if it's not duplicated url in db given url in same user.

class rss {     long id     string link     static belongsto = [user:user] }  class user {     long id     long uid //facebook     string name     static hasmany = [rss:rss] }  def addrss(){ //logic url valid or not ...  def user = user.findbyuid(data.id) //get user uid , uid, can rss url  //and compare if(db_url == given_url) ... } 

i tried many ways , had no success.

you use 1 of findorsavewhere or findorcreatewhere methods

def url = 'some url user' //data.url assume def user = user.findbyuid(data.id) rss.findorsavewhere(url: url, user: user) 

if it's in db fetch if not create you. documentation explains difference between *save* , *create*


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -