Breeze在将外键属性设置为null后为其指定默认值
我们仍在使用Northwind数据库测试Breeze,我们遇到了一个奇怪的行为 首先,我几乎可以肯定这不是一个bug,它不可能是,它是如此基本的操作 我们有一个产品实体,我们将其SupplierID设置为null(外键可以为null),如下所示Breeze在将外键属性设置为null后为其指定默认值,breeze,Breeze,我们仍在使用Northwind数据库测试Breeze,我们遇到了一个奇怪的行为 首先,我几乎可以肯定这不是一个bug,它不可能是,它是如此基本的操作 我们有一个产品实体,我们将其SupplierID设置为null(外键可以为null),如下所示 product.SupplierID(null) firstProduct.SupplierID(null); firstProduct.SupplierID(null); 在微风吹过之后,做这些 将产品的SupplierID值设置为
product.SupplierID(null)
firstProduct.SupplierID(null);
firstProduct.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表的key属性的默认值,该值为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?");
}
结果是,
另一件有趣的事情是,如果我们像这样设置两次这个值
product.SupplierID(null)
firstProduct.SupplierID(null);
firstProduct.SupplierID(null);
考试通过了,
我希望这个样本足以重现这种行为
提前感谢。这是一个bug,已在V0.80.3中修复,并可在breeze网站上获得。。。感谢单元测试;这真的很有帮助 这是一个bug,已在V0.80.3中修复,并可在breeze网站上获得。。。感谢单元测试;这真的很有帮助 Umut,请让我们知道这是否解决了您的问题。它工作得很好,Jay,非常感谢。我还要再次感谢你提供了这么好的工具:)嗯,请让我们知道这是否解决了你的问题。它工作得很好,杰,非常感谢。我还要再次感谢您提供了这么好的工具:)