groovy - Create a Grails Domain mapping for a foreign key that is connected to the composite primary key of another Domain -


how can reference 2 columns (which composite primary key) of grails domain composite primary key of domain class? in scenario, there one-to-one relationship between ceo toagency , agency branch.

i can map ceo agency since involves 1 column: ceo.id == agency.ceo_id. cannot map branch agency using 2 columns: agency.id == branch.agency_id , agency.main_branch_id == branch.branch_id.

class ceo {     ..... }  class agency {     .....     ceo ceo     branch mainbranch      static mapping = {         .....         ceo column: 'ceo_id'         /* tried using mapping doesn't work         mainbranch {             agencyid column: 'id',             branchid column: 'main_branch_id'         }         */         .....     } }  class branch {     .....     integer agencyid     integer branchid      static mapping = {         .....         id composite: ['agencyid', 'branchid']         .....     }      static constraints = {         .....         branchid unique: 'agencyid'         .....     } } 

please try use following technique agency class:

 class agency {      .....      ceo ceo      branch mainbranch       static mapping = {      .....      ceo column: 'ceo_id'      columns {         mainbranch {             column name: "firstname"             column name: "lastname"         }      }  .....  } 

reference here - section 6.5.2.5 composite primary keys.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -