|
Mikes writes here :
http://little418.com/2009/05/validate-that-a-grails-hasmany-relationship-has-at-least-one-child.html about constraining a hasMany relationship which is pretty straighforward, because he just checks for size. How can I find out if there isn't two left-rear tires though ? class Tire { // Note String tire_type // left-rear, right-rear.... static belongsTo = [car:Car] } class Car { String licence_number static hasMany = [tires:Tire] } I want to write a custom validator to find out if there isn't already a left-rear tire for a Car, in it's own hasMany relationship. Therefore, I need to reach the --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
This might help.... and explain some pitfalls:
http://johnrellis.blogspot.com/2009/09/grails-constraints-across-relationships.html On Thu, Apr 1, 2010 at 10:15 AM, Peter Willis <[hidden email]> wrote: Mikes writes here : |
|
In reply to this post by Peter Willis-5
Sorry, got sent out to early.
tires validator: { obj, car -> car.tires.find { it.tire_type == obj // ?? What here ? obj.tire_type doesn't seem to be working } obj is an instance of the collection.. and both car.tires and obj.tires are the same.. even when I do a addToTires ... How can I do this check ? Note. I am not really working with cars or tires. On 4/1/10, Peter Willis <[hidden email]> wrote: > Mikes writes here : > http://little418.com/2009/05/validate-that-a-grails-hasmany-relationship-has-at-least-one-child.html > > about constraining a hasMany relationship which is pretty > straighforward, because he just checks for size. > > How can I find out if there isn't two left-rear tires though ? > > class Tire { // Note > String tire_type // left-rear, right-rear.... > static belongsTo = [car:Car] > } > > class Car { > String licence_number > static hasMany = [tires:Tire] > } > > I want to write a custom validator to find out if there isn't already > a left-rear tire for a Car, in it's own hasMany relationship. > Therefore, I need to reach the > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Thanks, I will try that. That's exactly what I am looking for.
Although I really would like to get hold hold of that object being added, because I have to validate it's value exist in another separate domain. On 4/1/10, Peter Willis <[hidden email]> wrote: > Sorry, got sent out to early. > > tires validator: { obj, car -> > car.tires.find { it.tire_type == obj // ?? What here ? > obj.tire_type doesn't seem to be working > } > > obj is an instance of the collection.. and both car.tires and > obj.tires are the same.. even when I do a addToTires ... > > How can I do this check ? > > Note. I am not really working with cars or tires. > > On 4/1/10, Peter Willis <[hidden email]> wrote: >> Mikes writes here : >> http://little418.com/2009/05/validate-that-a-grails-hasmany-relationship-has-at-least-one-child.html >> >> about constraining a hasMany relationship which is pretty >> straighforward, because he just checks for size. >> >> How can I find out if there isn't two left-rear tires though ? >> >> class Tire { // Note >> String tire_type // left-rear, right-rear.... >> static belongsTo = [car:Car] >> } >> >> class Car { >> String licence_number >> static hasMany = [tires:Tire] >> } >> >> I want to write a custom validator to find out if there isn't already >> a left-rear tire for a Car, in it's own hasMany relationship. >> Therefore, I need to reach the >> > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Could you use a custom validator as well as the unique : 'parent' option?
An example might help. On Thu, Apr 1, 2010 at 10:35 AM, Peter Willis <[hidden email]> wrote: Thanks, I will try that. That's exactly what I am looking for. |
| Powered by Nabble | Edit this page |
