0

I have 2 classes Person and and Designation. I am using @Resource annotation to make them restful

            import grails.rest.Resource
            @Resource(formats=['json', 'xml'])

               class Person {
                               String name 
                               static belongsTo = [designation:Designation] 

                            static constraints = {  }
                            }

and Designation class is

                import grails.rest.Resource
                @Resource(formats=['json', 'xml'])

                   class Designation {
                                   Long designationId
                                   String name 


                                static constraints = {  }
                                }     

Since I'm using grails default resource url mapping like

"/app/person"(resources: "person",  includes: ['index', 'show', 'save', 'update', 'delete', 'create', 'patch'])

I want to prform insert to Person object using POST request to /app/person with json data. Since designation is belongs to another object , I need to pass only a reference to an existing Designation object id how do i pass this via json? what is the json format to do the same? or can I access the params in beforeInsert() method of Person class , so that i can manually get designatioId , then find Designation object with that id , then assign it new Person object?

1 Answers1

0

I think if you add:

designation: { id: 123 }

to your person JSON, that should do the trick.

Gregg
  • 34,973
  • 19
  • 109
  • 214