|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Constraints and linked objectsHi everyone,
I just started working with Grails, and I'm pretty impressed so far. I have one unresolved question that involves constraints: I have a domain class, Order, which is linked to at most one Customer object. Before saving an Order object, I would like to ensure that the linked Customer object has at least one of two attributes set (e.g. phoneNumber or eMail). For reasons beyond my control (existing customer database), it is not enough to apply the constraint on the creation of new Customer objects. I did not figure out so far how this is possible. Any suggestions are greatly appreciated! Best regards, Flavio --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Constraints and linked objectsHi Flavio,
in this case I think the better way is generating some checks before save invokation (on Order domain classes)... You need to check your "constraints" by hand... but will be works ;) bye Marco Flavio Spaini wrote: > Hi everyone, > > I just started working with Grails, and I'm pretty impressed so far. I > have one unresolved question that involves constraints: > > I have a domain class, Order, which is linked to at most one Customer > object. Before saving an Order object, I would like to ensure that the > linked Customer object has at least one of two attributes set (e.g. > phoneNumber or eMail). For reasons beyond my control (existing > customer database), it is not enough to apply the constraint on the > creation of new Customer objects. I did not figure out so far how this > is possible. > > Any suggestions are greatly appreciated! > > Best regards, > > Flavio > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > -- Dott. Ing. Mornati Marco Byte-Code s.r.l via Antonio Cechov, 1 San Giuliano Milanese (MI) E-Mail: mmornati@... --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Constraints and linked objectsHi Marco,
Thank you for your reply. Would you suggest to do this in beforeInsert? If so, can I throw an exception there? Thanks again, Flavio On 04.07.2008, at 17:34, Marco Mornati wrote: > Hi Flavio, > > in this case I think the better way is generating some checks before > save invokation (on Order domain classes)... You need to check your > "constraints" by hand... but will be works ;) > > bye > Marco > > Flavio Spaini wrote: >> Hi everyone, >> >> I just started working with Grails, and I'm pretty impressed so >> far. I have one unresolved question that involves constraints: >> >> I have a domain class, Order, which is linked to at most one >> Customer object. Before saving an Order object, I would like to >> ensure that the linked Customer object has at least one of two >> attributes set (e.g. phoneNumber or eMail). For reasons beyond my >> control (existing customer database), it is not enough to apply the >> constraint on the creation of new Customer objects. I did not >> figure out so far how this is possible. >> >> Any suggestions are greatly appreciated! >> >> Best regards, >> >> Flavio >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> > > > -- > Dott. Ing. Mornati Marco > Byte-Code s.r.l > via Antonio Cechov, 1 > San Giuliano Milanese (MI) > E-Mail: mmornati@... > > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Constraints and linked objectsFor those interested:
I solved my little problem quite easily. I slimmed down the code a bit to make it easier to read: static constraints = { customer(validator: { if (it.phoneNumber.equals("") && it.email.equals("")) { return false; } }); } On 04.07.2008, at 17:34, Marco Mornati wrote: > Hi Flavio, > > in this case I think the better way is generating some checks before > save invokation (on Order domain classes)... You need to check your > "constraints" by hand... but will be works ;) > > bye > Marco > > Flavio Spaini wrote: >> Hi everyone, >> >> I just started working with Grails, and I'm pretty impressed so >> far. I have one unresolved question that involves constraints: >> >> I have a domain class, Order, which is linked to at most one >> Customer object. Before saving an Order object, I would like to >> ensure that the linked Customer object has at least one of two >> attributes set (e.g. phoneNumber or eMail). For reasons beyond my >> control (existing customer database), it is not enough to apply the >> constraint on the creation of new Customer objects. I did not >> figure out so far how this is possible. >> >> Any suggestions are greatly appreciated! >> >> Best regards, >> >> Flavio >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> > > > -- > Dott. Ing. Mornati Marco > Byte-Code s.r.l > via Antonio Cechov, 1 > San Giuliano Milanese (MI) > E-Mail: mmornati@... > > > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Free embeddable forum powered by Nabble | Forum Help |