Skip to content

Commit 66657c1

Browse files
committed
Add dotted cfc path many-to-one relationship test (resolves via Application mapping)
1 parent cc1d7cf commit 66657c1

5 files changed

Lines changed: 65 additions & 0 deletions

File tree

tests/mapping/relationships.cfc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ component extends="org.lucee.cfml.test.LuceeTestCase" labels="orm" {
4444
expect( trim( result.filecontent ) ).toBe( "ok" );
4545
});
4646

47+
it( "many-to-one with dotted cfc path resolves via Application mapping", function() {
48+
var result = _InternalRequest( template: "#uri()#/dottedCfcPath/test.cfm" );
49+
expect( trim( result.filecontent ) ).toBe( "ok" );
50+
});
51+
4752
});
4853

4954
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
component {
2+
this.name = "test-relationships-dotted-#hash( getCurrentTemplatePath() )#";
3+
this.datasource = server.getDatasource( "h2", server._getTempDir( "orm-relationships-dotted" ) );
4+
this.ormEnabled = true;
5+
this.mappings = {
6+
"/dotted" = getDirectoryFromPath( getCurrentTemplatePath() ) & "entities"
7+
};
8+
this.ormSettings = {
9+
dbcreate: "dropcreate",
10+
cfclocation: [ getDirectoryFromPath( getCurrentTemplatePath() ) & "entities" ]
11+
};
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
component accessors="true" persistent="true" {
2+
3+
property
4+
name ="id"
5+
type ="string"
6+
fieldtype="id"
7+
ormtype ="string";
8+
property name="name" type="string";
9+
10+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
component accessors="true" persistent="true" {
2+
3+
property
4+
name ="id"
5+
type ="string"
6+
fieldtype="id"
7+
ormtype ="string";
8+
property name="model" type="string";
9+
property
10+
name ="garage"
11+
fieldtype="many-to-one"
12+
cfc ="dotted.Garage"
13+
fkcolumn ="garageID";
14+
15+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<cfscript>
2+
// Adam Tuttle 2019 reported that Lucee rejects fully-qualified CFC paths in
3+
// relationship cfc="..." attributes (e.g. cfc="orm.ems.Person"), requiring bare
4+
// names instead. This test exercises the dotted form via a /dotted mapping
5+
// configured in Application.cfc, asserting the relationship resolves correctly.
6+
7+
garage = entityNew( "Garage", { id: createUUID(), name: "Downtown Auto" } );
8+
entitySave( garage );
9+
10+
vehicle = entityNew( "Vehicle", { id: createUUID(), model: "Civic", garage: garage } );
11+
entitySave( vehicle );
12+
ormFlush();
13+
14+
// reload and verify many-to-one resolved through dotted cfc="dotted.Garage"
15+
ormClearSession();
16+
loaded = entityLoadByPK( "Vehicle", vehicle.getId() );
17+
if ( isNull( loaded.getGarage() ) )
18+
throw( message="dotted cfc path: garage should not be null" );
19+
if ( loaded.getGarage().getName() != "Downtown Auto" )
20+
throw( message="dotted cfc path: expected Downtown Auto, got #loaded.getGarage().getName()#" );
21+
22+
echo( "ok" );
23+
</cfscript>

0 commit comments

Comments
 (0)