Breeze を Northwind データベースでテストしている最中ですが、奇妙な動作に遭遇しました。
まず、これはバグではなく、バグではないはずです。これは非常に基本的な操作です。
製品エンティティがあり、その SupplierID を次のように null (外部キーは null 可能) に設定します。
product.SupplierID(null)
このそよ風の後、これらを行い、
- 製品の SupplierID 値を null に設定します
- 製品のサプライヤーを null に設定
- 製品の SupplierID を 0 に設定します
これにより、外部キー例外が発生します。
おそらくこれは単純な問題です。何かを見逃している必要があります。私の同僚の 1 人が今朝からこれを解決しようとしていますが、うまくいきません。
彼は、この割り当ての後、簡単にこれを 2 回呼び出し (1 回は SupplierID 用、もう 1 回は SupplierID 用)、それらに null を割り当てることに気付きました。
result = ko.computed({
read: target, //always return the original observables value
write: function(newValue) {
instance._$interceptor(property, newValue, target);
return instance;
}
});
このそよ風が外部キーをチェックし、この行を実行した後、
if (property.relatedDataProperties) {
if (!entityAspect.entityState.isDeleted()) {
var inverseKeyProps = property.entityType.keyProperties;
inverseKeyProps.forEach(function(keyProp, i ) {
var relatedValue = newValue ? newValue.getProperty(keyProp.name) : keyProp.defaultValue;
that.setProperty(property.relatedDataProperties[i].name, relatedValue);
});
}
興味深いことに、この行は値が null (product.SupplierID の場合) かどうかをチェックし、null の場合は Supplier テーブルのキー プロパティの既定値に設定し、値は 0 です (主キーであるため、null に設定できません)。
バージョン 0.80.2 に更新しましたが、同じ動作をしています。
前もって感謝します。
[アップデート]
これが私たちのテストです。
test("set foreign key property to null", 3, function () {
var productQuery = new EntityQuery("Products").take(1)
.expand("Supplier");
stop();
queryForOne(newEm, productQuery, "First Product")
.then(assertProductSetSupplierIDToNull)
.fail(handleFail)
.fin(start);
});
function assertProductSetSupplierIDToNull(data) {
var products = data.results;
var firstProduct = products[0];
ok(firstProduct.SupplierID(), "SupplierID is "+firstProduct.SupplierID());
firstProduct.SupplierID(null);
equal(firstProduct.SupplierID(), null, "is SupplierID null?");
}
結果は、
もう 1 つの興味深い点は、この値をこのように 2 回設定すると、
firstProduct.SupplierID(null);
firstProduct.SupplierID(null);
テストに合格し、
この動作を再現するには、このサンプルで十分だと思います。
前もって感謝します。