以下の Grails コードは.save()
、Foo オブジェクトを試行すると、次の例外をスローします。
org.hibernate.TransientObjectException/
org.springframework.dao.InvalidDataAccessApiUsageException:
object references an unsaved transient instance -
save the transient instance before flushing: Bar
HTTPパラメーターからドメインオブジェクトを自動的に取り込むことに関連して、GORMセマンティクスの一部を見逃していると思います。
私の質問は簡単です:
- 上記の例外を取得せずに Foo オブジェクトを作成して保存する正しい方法は何ですか?
モデル:
class Foo {
Bar bar
}
意見:
<g:form id="${foo.id}">
<g:select name="foo.bar.id" from="${Bar.list()}" />
</g:form>
コントローラ:
class FooController {
def fooAction = {
Foo foo = new Foo(params)
foo.save()
[ foo: foo ]
}
}