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() ); + } ); } ); }