这是一个延续this https://stackoverflow.com/questions/6959777/grails-chained-drop-down问题。
我有一个Address
包含基本街道地址信息的类。我也有一个User
具有属性的类physicalAddress
, mailingAddress
, cargoDestinations
, and cargoSources
. The User
类看起来像这样:
class User {
String username
String password
String firstName
String lastName
String businessName
String phoneNumber
Address physicalAddress
Address mailingAddress
static hasMany = [accounts:Account, cargoSources:Address, cargoDestinations:Address, cargoes:Cargo, loadsLogged:Load, loadsDelivered:Load]
Set accounts, cargoSources, cargoDestinations, cargoes
static mappedBy = [loadsLogged:"loggedBy", loadsDelivered:"deliveredBy"]
//some other stuff after this
And the Address
类看起来像这样:
class Address {
static belongsTo = [user:User]
String streetAddress
String city
String state
String zip
BigDecimal taxRate
//some other stuff after this
我按照教程进行操作here http://moongrails.blogspot.com/2008/12/grails-ajax-chained-select.html大多数情况下。在第 5 步中,我的模板如下所示:
<g:select
from="${account.user.cargoDestinations}"
name="cargoDestinations" value="">
</g:select>
问题是,而不是只返回cargoDestinations
,模板返回与该用户关联的所有地址。如果我改变from="${account.user.cargoDestinations}"
to from="${account.user.physicalAddress}"
or from="${account.user.mailingAddress}"
我得到了预期的结果,所以我知道我的问题与cargoDestinations
变量被映射。我怎样才能在不改变我的类文件太多的情况下解决这个问题?