2
votes

i have 2 domain classes as shown below

class User
 {
  String userId
  String userName
  SsGroups groups
  **static hasMany = [groups:SsGroups]
  static belongsTo=SsGroups**
  }

 class SsGroups
  {
  String groupId
  **static hasMany = [users:User]**

  }

i implemented many to many relation,its working well and fine.now i wanna select multiple groups from SsGroups to a single User,here is the code in User,create.gsp.

<g:select name="groups.id" multiple="yes" from="${app.SsGroups.list()}"  optionKey="id"   value="${userInstance?.groups?.id}"  />

but while saving there is an error saying Error 500: Executing action [save] of controller [app.UserController] caused exception: groovy.lang.MissingMethodException: No signature of method: app.SsGroups.get() is applicable for argument types: (java.lang.String, java.lang.String) values: [2, 3] Possible solutions: get(java.lang.Object), getId(), getAt(java.lang.String), list(), getAll(), getLog(). please can you guide me how to select multiple values and store those??

This controller User:

def save = {
    def userInstance = new User(params)
    if (userInstance.save(flush: true)) {
        flash.message = "${message(code: 'default.created.message', args: [message(code: 'user.label', default: 'User'), userInstance.id])}"
        redirect(action: "show", id: userInstance.id)
    }

there is no get() method in it.Where do i need to write getAll() method?

1
If would be helpful to show you controller method\code. - Michael J. Lee

1 Answers

0
votes

It's because the params.groups.id is returning an array of selected groups in your multiple select control, in this case '[2, 3]'. Use the getAll method instead of the get method. The getAll supports the array argument.