From d5a1d26b03a3243232ae7bfa81b7cc94f4579395 Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Sat, 22 Aug 2026 04:59:16 -0600 Subject: [PATCH] test: cover has one through initial constraints (#119) --- tests/resources/app/models/User.cfc | 4 ++++ .../BaseEntity/Relationships/HasOneThroughSpec.cfc | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/tests/resources/app/models/User.cfc b/tests/resources/app/models/User.cfc index 2c70b699..e6b2a46e 100644 --- a/tests/resources/app/models/User.cfc +++ b/tests/resources/app/models/User.cfc @@ -216,6 +216,10 @@ component extends="quick.models.BaseEntity" accessors="true" { return hasOne( "Post", "post_pk", "favoritePost_id" ); } + function favoritePostAuthor() { + return hasOneThrough( [ "favoritePost", "author" ] ); + } + function latestPostWithEmptyDefault() { return hasOne( "Post", "user_id" ).latest().withDefault(); } diff --git a/tests/specs/integration/BaseEntity/Relationships/HasOneThroughSpec.cfc b/tests/specs/integration/BaseEntity/Relationships/HasOneThroughSpec.cfc index 216ea16d..ad221b52 100644 --- a/tests/specs/integration/BaseEntity/Relationships/HasOneThroughSpec.cfc +++ b/tests/specs/integration/BaseEntity/Relationships/HasOneThroughSpec.cfc @@ -9,6 +9,13 @@ component extends="tests.resources.ModuleIntegrationSpec" { expect( country.getLatestPost().getPost_Pk() ).toBe( 523526 ); expect( country.getLatestPost().getBody() ).toBe( "My second awesome post body" ); } ); + + it( "can start with a hasOne relationship", function() { + var user = getInstance( "User" ).findOrFail( 1 ); + + expect( user.getFavoritePostAuthor() ).notToBeNull(); + expect( user.getFavoritePostAuthor().getId() ).toBe( user.getId() ); + } ); } ); }