Breeze在将外键属性设置为null后为其指定默认值

Breeze在将外键属性设置为null后为其指定默认值,breeze,Breeze,我们仍在使用Northwind数据库测试Breeze,我们遇到了一个奇怪的行为 首先,我几乎可以肯定这不是一个bug,它不可能是,它是如此基本的操作 我们有一个产品实体,我们将其SupplierID设置为null(外键可以为null),如下所示 product.SupplierID(null) firstProduct.SupplierID(null); firstProduct.SupplierID(null); 在微风吹过之后,做这些 将产品的SupplierID值设置为

我们仍在使用Northwind数据库测试Breeze,我们遇到了一个奇怪的行为

首先,我几乎可以肯定这不是一个bug,它不可能是,它是如此基本的操作

我们有一个产品实体,我们将其SupplierID设置为null(外键可以为null),如下所示

product.SupplierID(null)
    firstProduct.SupplierID(null);
    firstProduct.SupplierID(null);
在微风吹过之后,做这些

  • 将产品的SupplierID值设置为空
  • 将产品的供应商设置为空
  • 将产品的供应商ID设置为0
  • 这会导致外键异常

    也许这是一个简单的问题,我们必须错过一些东西,我的一个同事从今天早上开始就试图解决这个问题,没有运气

    他发现在这个赋值之后,breeze调用这个函数两次(一次用于SupplierID,另一次用于SupplierID),并将它们赋值为空

    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,非常感谢。我还要再次感谢你提供了这么好的工具:)嗯,请让我们知道这是否解决了你的问题。它工作得很好,杰,非常感谢。我还要再次感谢您提供了这么好的工具:)