私は Grails 2.0.4 を使用していますが、次のエラーが表示されます。
メソッドの署名なし: com.example.User.addToDefaultStorePricingProfiles() は、引数の型に適用されます: (com.example.PricingProfile) 値: bindData() 行の [com.example.PricingProfile : 5]。既に保持されている PricingProfiles を追加する前に、最初にユーザーとストアを保存する必要がありますか? または、これを行うためのより良い方法はありますか?
モデル
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]
}
ストアの価格プロファイルのビューで複数選択を使用しています
<g:select from="${retailer.pricingProfiles}" name="defaultStore.pricingProfiles" value="${user?.defaultStore?.pricingProfiles*.id}" multiple="multiple" optionKey="id" optionValue="name" class="pricingProfiles" />
ストアコントローラー
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])
}
}
パラメータ:
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