Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

withcount throws error (v10.0.0, was working on 7.3.1) #258

Open
davidAtInleague opened this issue Jan 14, 2025 · 0 comments
Open

withcount throws error (v10.0.0, was working on 7.3.1) #258

davidAtInleague opened this issue Jan 14, 2025 · 0 comments

Comments

@davidAtInleague
Copy link
Contributor

davidAtInleague commented Jan 14, 2025

Maybe this is from a breaking change, but it seems like it should work so maybe a bug. This is as minimal a repro as I could muster up.

getInstance("A").initTable();
getInstance("B").initTable();
getInstance("C").initTable();

idA = queryExecute("insert into a output inserted.IDa default values").IDa;
idCs = queryExecute("
	insert into c (idA, cgroupID, [data]) values (#idA#, 1, 'val1'), (#idA#, 1, 'val2'); -- should be reflect in count
	insert into c (idA, cgroupID, [data]) values (#idA#, 2, 'val1'), (#idA#, 2, 'val2') -- should not be reflected in count
")

queryExecute("insert into b (IDa, cgroupID) values (#idA#, 1)", {}, {returnType: "array"})

// quick 7.3.1 : returns 2 (as expected)
// quick 10.0.0 : throws Invalid call of the function [qualifyColumn] , first Argument [column] is of invalid type, Cannot cast Object type [Array] to a value of type [string]
//                from modules/quick/models/Relationships/HasManyDeep.cfc:250
writedump(
	getInstance("A")
		.withCount({"cs as cs": () => {}})
		.asQuery()
		.firstOrFail().cs
);
// A.cfc
component extends="quick.models.BaseEntity" table="A" accessors=true {
    property name="IDa" sqltype="integer";

    variables._key = "IDa";

    function Bs() {
		return hasMany(
			relationName = "B",
			foreignKey = "IDa",
			localKey = "IDa"
		);
	}

	function Cs() {
		return hasManyThrough(
			relationships = [ "Bs", "Cs" ]
		)
	}

    function initTable() {
        queryExecute("
            drop table if exists a;
            create table a(IDa int not null identity primary key);
        ");
    }
}
// B.cfc
component extends="quick.models.BaseEntity" table="B" accessors=true {
	property name="IDa" sqltype="integer";
	property name="cgroupID" sqltype="integer";

    variables._key = ["IDa", "cgroupID"];

    function Cs() {
		return hasMany(
			relationName = "C",
			foreignKey = ["IDa", "cgroupID"],
			localKey = ["IDa", "cgroupID"]
		);
	}

	function initTable() {
		queryExecute("
			drop table if exists b;
			create table b(IDa int not null, cgroupID int not null);
		");
	}
}
// C.cfc
component extends="quick.models.BaseEntity" table="C" accessors=true {
    property name="IDa" sqltype="integer";
	property name="cgroupID" sqltype="integer";
    property name="data" sqltype="varchar";

    variables._key = "cgroupID";

    function initTable() {
        queryExecute("
            drop table if exists c;
            create table c(IDa int not null, cgroupID int not null, [data] varchar(max));
        ");
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant