外部キーの場合、トルクを取得して 0 の値を null に変換する方法はありますか?
次のスキーマがあります。
<table name="juser" idMethod="native">
<column name="id" primaryKey="true" required="true" type="INTEGER"/>
<column name="name" required="true" size="2147483647" type="VARCHAR"/>
</table>
<table name="juserDepend" idMethod="native">
<column name="id" primaryKey="true" required="true" type="INTEGER"/>
<column name="juserRef" required="false" type="INTEGER"/>
<foreign-key foreignTable="juser">
<reference foreign="id" local="juserRef"/>
</foreign-key>
</table>
そして、私のテーブルはこのSQLで作成されます:
create table juserDepend(id serial not null primary key,
juserRef int,
name text not null,
foreign key(juserRef) references juser(id) on delete cascade
);
ご覧のとおり、JuserDepend には juser テーブルへのオプションの外部キー (juserRef) がありますが、それを理解するためのトルクが得られないようです。現在、juserRef に null 値を持つ juserDepend オブジェクトを保存する方法がありません。これは、トルクが整数値 0 を使用し、それが有効な外部キーではないため、データベースが文句を言うためです。
私の推奨する解決策は、null が許可されているすべての外部キーに対して、0 を null に単純に変換することです。これは可能ですか?