|
I'm using the Airport - Flight for a delete rule example:
class Airport {
String name
static hasMany = [flights: Flight]
}class Flight {
|
|
> Airport a = new Airport(name: "Gatwick").save(flush: true)
> > Flight f = new Flight(numberFlight: "BA3430", airport: a).save(flush:true) that is why addTo methods were added :-) You are missing a.flights << f in this setup. --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Right, but you don't really need that since this is a somewhat contrived example (but typical of integration tests).
It would be rare to create something and delete it in the same session - it'd usually be two separate requests and sessions. When you don't use addTo or manually add the flight to the flights collection, the in-memory state isn't the same as the database state. To make this more realistic, clear the session to force a re-load from the database (the airport is still cached in the session, so you're just getting the inconsistent instance from before). Add this line Airport.withSession { session -> session.clear() } before the Airport.findByName call and it will work. Burt
|
|
Thanks for the explanation!
Clearing the session works. Regards, Sérgio
On Fri, Jul 20, 2012 at 12:20 PM, burtbeckwith <[hidden email]> wrote: Right, but you don't really need that since this is a somewhat contrived |
| Powered by Nabble | Edit this page |
