findOrCreateBy
如果找不到匹配的对象,我正在尝试使用它来搜索对象或实例化一个对象,但它没有按预期工作。
这就是我所拥有的:
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
我究竟做错了什么?为什么fooType
没有正确设置?这是预期的行为还是 Grails 中的错误?