gorm - Grails: Prevent cascading association between two domain classes with multiple relationships -


consider 2 domain classes; job , quote.

a job has many quotes job has accepted quote. accepted quote nullable , should set once particular quote has been accepted user. have relationships mapped follows (simplified purpose of illustration).

class job {     string title     quote acceptedquote    }  class quote {     job job     bigdecimal quoteamount  } 

the resultant tables require (at least aesthetically) problem arises when go , save quote. quote saved jobid per logic in code unfortunately quote's id gets saved in job table acceptedquote. there anyway block cascading association? code persists quote basic , looks following;

def quoteinstance = new quote(job: jobinstance, quoteamount: amount) if (quoteinstance.save(flush: true)) {    render view: 'show', model: [quoteinstance: quoteinstance]    break } 

obviously jobinstance passed quote constructor save association in quote table not know how prevent quote id saving job table accepted quote. maybe gorm strategy using not satisfy these requirements?

any appreciated.

this may not looking model little differently - have accepted flag in quote domain:

class job {     string title     static hasmany = [quotes: quote] }  class quote {     static belongsto = [job: job]     bigdecimal quoteamount     boolean accepted } 

then persistence this:

jobinstance.addtoquotes(new quote(quoteamount: 123.34, accepted: false)) //or true 

and no worries regarding original problem.

you add transient , getter job class accepted quote

class job {     string title     static hasmany = [quotes: quote]      static transients = ['acceptedquote']      quote getacceptedquote() {         return quote.findbyjobandaccepted(this, true)     }  } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -