quick icon indicating copy to clipboard operation
quick copied to clipboard

refresh does not reload scopes

Open davidAtInleague opened this issue 1 year ago • 0 comments

component table="RMME_A" extends="quick.models.BaseEntity" accessors=true {
    property name="id_a" type="numeric" sqltype="int";
    property name="v" type="string" sqltype="varchar";
    
    variables._key = "id_a";
    function keyType() {
		return variables._wirebox.getInstance( "NullKeyType@quick" ); // the key comes from Stripe and is not generated locally
	}

    function scopeWithComputedValue( qb ) {
        qb.appendVirtualAttribute( "computedValue" )
        qb.selectRaw("'the value in the [v] column is: <<<' + [v] + '>>>' as computedValue")
    }
}
///////
queryExecute("
	drop table if exists rmme_a;
	create table rmme_a(id_a int, v varchar(max));
")

getInstance("RMME_A").create({id_a:1, v: "AAA"})

x = getInstance("RMME_A").whereID_A(1).withComputedValue().firstOrFail()
writedump(x.getComputedValue()) // "the value in the [v] column is: <<<AAA>>>"
x.update({v: "BBB"})
x = x.refresh()
writedump(x.getV()) // "BBB", ok
writedump(x.getComputedValue()) // "the value in the [v] column is: <<<AAA>>>", computed value out of sync with actual value after a refresh


x = getInstance("RMME_A").whereID_A(1).withComputedValue().firstOrFail()
writedump(x.getComputedValue()) // "the value in the [v] column is: <<<BBB>>>", ok after full firstOrFail reload

abort;

This can lead to entities winding up in inconsistent states, where computed values from scopes are no longer in sync with actually refreshed data.

This behavior appears unchanged from Quick4, maybe it just needs to be documented.

davidAtInleague avatar May 12 '23 19:05 davidAtInleague