I'm trying to use findOrCreateBy
to search for an object or instantiate one if I can't find one that matches, but it isn't working as I expected.
This is what I have:
String myBaz = "some unique string"
FooType myFooType = FooType.findByName("Large")
// The Foo table is empty, so this should give me a new Foo
Foo myFoo = Foo.findOrCreateByBazAndFooType(myBaz, myFooType)
assert myFoo.baz == myBaz
assert myFoo.fooType == myFooType // Fails because myFoo.fooType is null,
// but should be set to myFooType
What am I doing wrong? Why is the fooType
not being properly set? Is this expected behavior or is this a bug in Grails?