Skip to content
Vahid Hedayati edited this page May 22, 2014 · 2 revisions

Example3 : simple belongsTo example

So far all my examples have worked on relationship of

FirstTable hasMany=[secondTable: SecondTable]
SecondTable FirstTable firstable

I have set this up to show its the same for belongsTo=[firstable: FirstTable]

so we have:

class Table1 {

String aName
static hasMany=[tableb: Table2]
    static constraints = {
    }
}


class Table2 {
String bName
static belongsTo=[tablea: Table1]
    static constraints = {
    }
}

This works identical to the other declaration method:



<form method=post action=example5>

<g:selectPrimary id="Test1" name="Test1"
        domain='ajaxdependancyselectexample.Table1'
        searchField='aName'
        collectField='id'
        
        domain2='ajaxdependancyselectexample.Table2'
        bindid="tablea.id"
        searchField2='bName'
        collectField2='id'

        noSelection="['': 'Please choose test1']"
        setId="Test2ID"
        value=''/>

<g:select name="test2" id="Test2ID" optionKey="id" optionValue="bName" from="[]" required="required" noSelection="['': 'Please choose test1']" />
<input type=submit value=go>
    </form>

Clone this wiki locally