java - How to iterate and add each "many" in a one-to-many class -
i have 2 classes. orderslip class has one-to-many relationship ordereditemdescription.
class orderslip { string employeeid int serving int tablenumber static hasmany = [ordereditemdescription: ordereditemdescription] } class ordereditemdescription { menuitem menuitem menuitemprogressstatus progress//progress string descriptionoforder int quantity = 1 static belongsto = orderslip } now problem how iterate ordereditemdescription when update orderslip can add many ordereditemdescriptions along properties.
def updateorderslip(long id) { user currentuser = springsecurityservice.currentuser def orderslipinstance = table.get(id) //other codes ordereditemdescription here orderslipinstance.employeeid = currentuser.username orderslipinstance.serving= integer.parseint(params.serving) orderslipinstance.tablenumber= params.tablenumber render(action:'server') } im doing in gsp. im adding data dom add buttons. send order im hoping can update problem since im adding many g:hiddenfield each ordereditemdescription in summary

you should persisting each new instance ordereditemdescription somehow.
you can store in db upon click on add-button status flag set incomplete. when save whole order, must change incomplete complete.
another option keep items in http session. upon send order iterate through in-session items , persist them along order instance.
both ways have advantages , drawbacks, both useful.
Comments
Post a Comment