From 3dcd9873c494b113727cf6b6c80cb8206bbe4a87 Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Sat, 22 Aug 2026 05:02:36 -0600 Subject: [PATCH] test: compare whereHas through constraints (#116) --- .../Relationships/QueryingRelationshipsSpec.cfc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/specs/integration/BaseEntity/Relationships/QueryingRelationshipsSpec.cfc b/tests/specs/integration/BaseEntity/Relationships/QueryingRelationshipsSpec.cfc index b71997a9..36d5dafd 100644 --- a/tests/specs/integration/BaseEntity/Relationships/QueryingRelationshipsSpec.cfc +++ b/tests/specs/integration/BaseEntity/Relationships/QueryingRelationshipsSpec.cfc @@ -213,6 +213,19 @@ component extends="tests.resources.ModuleIntegrationSpec" { expect( countries ).toHaveLength( 2 ); } ); + it( "applies the same constraints as the expanded relationship path", function() { + var throughCountries = getInstance( "Country" ) + .whereHas( "posts", ( q ) => q.where( "post_pk", 321 ) ) + .get(); + var expandedCountries = getInstance( "Country" ) + .whereHas( "users.posts", ( q ) => q.where( "post_pk", 321 ) ) + .get(); + + expect( throughCountries ).toHaveLength( 1 ); + expect( throughCountries[ 1 ].getName() ).toBe( "Argentina" ); + expect( throughCountries[ 1 ].getId() ).toBe( expandedCountries[ 1 ].getId() ); + } ); + it( "can find only entities that have a related hasManyThrough entity through multiple levels", function() { var countries = getInstance( "Country" ).has( "comments" ).get(); expect( countries ).toBeArray();