has many - Adding, updating and removing associated classes in Grails -
i have following relations:
class host { static hasmany = [ips: hostip, groups: hostgroup] static belongsto = [hostgroup] string dns } class hostip { static belongsto: [host: host] string ip } class hostgroup { static hasmany = [ hosts: host ] string name }
i have form in gsp allows edition of host. have dynamic add-edit-remove list add, edit , delete new , current host ips, if host has 2 ips (ip1 , ip2), ip1 removed, ip2 modified ip3 , ip4 added, data sent controller:
original data displayed in form:
ips[0].id = 8 ips[0].ip = ip1 ips[1].id = 9 ips[1].ip = ip2
sent data when submitted:
ips[1].id = 9 ips[1].ip = ip3 ips[2].ip = ip4
this means, that, ip1 removed, neither id or ip sent (its fields removed form), , new ip4 sent (new dynamic field added), without id, doesn't exist yet. so, when doing binddata(host, params)
, , save()
, ip2 updated ip3, , ip4 created, ip1 not deleted. normal behaviour of binddata
? if not, can forced?
i'll ask groups relations in post...
regards , in advance.
using grails 2.3.7.
try add
static mapping = { ips cascade: 'all-delete-orphan' }
to host class. more, see http://grails.org/doc/latest/ref/database%20mapping/cascade.html (using configuration book deleted if removed (orphaned) author's books association.)
Comments
Post a Comment