I’m in Grails 2.0.4
I’m getting the error:
No signature of method: com.example.User.addToDefaultStorePricingProfiles() is applicable for argument types: (com.example.PricingProfile) values: [com.example.PricingProfile : 5] on the bindData() line. Do I have to save the User and Store first before adding the already-persisted PricingProfiles, or is there a better way to do this?
Models
class User {
transient springSecurityService
String username
String password
boolean enabled
boolean accountExpired
boolean accountLocked
boolean passwordExpired
Store defaultStore
Date dateCreated
Date lastUpdated
static hasMany = [orders: Order]
}
class Store {
String storeNumber
String name
PricingProfile defaultPricingProfile
static belongsTo = [retailer: Retailer]
static hasMany = [pricingProfiles: PricingProfile]
}
class PricingProfile {
String name
static belongsTo = [retailer: Retailer]
}
I’m using a multiple select in the view for pricingProfiles on the Store
<g:select from="${retailer.pricingProfiles}" name="defaultStore.pricingProfiles" value="${user?.defaultStore?.pricingProfiles*.id}" multiple="multiple" optionKey="id" optionValue="name" class="pricingProfiles" />
Store Controller
def save() {
Retailer retailer = Retailer.get(params.retailer)
User user = new User()
user.defaultStore = new Store()
bindData(user, params)
user.validate()
user.defaultStore.validate()
if (user.hasErrors() || user.defaultStore.hasErrors()) {
log.error("Error saving store: ${user.errors.fieldErrors} ${user.defaultStore.errors.fieldErrors}")
flash.storeError = "Please correct the errors below"
render(view: 'create')
} else {
retailer.addToStores(user.defaultStore)
retailer.addToUsers(user)
retailer.save(failOnError: true, flush: true)
flash.confirm = "Store ${user.defaultStore.storeNumber} successfully added"
redirect (action: 'list', params: [retailer: retailer.id])
}
}
params:
defaultStore.pricingProfiles: 2
defaultStore.pricingProfiles: 3
defaultStore.pricingProfiles: 4
defaultStore.defaultPricingProfile.id: 2
retailer: 2
submitStore: Save
defaultStore.storeNumber: 888
username: wert
password: wert
defaultStore.name: Fake Store
My solution was to add the pricingProfiles manually.
Then in the controller,