Skip to content

Commit

Permalink
fix(ChildEntities): Fix qualifying column on discriminated joined ent…
Browse files Browse the repository at this point in the history
…ities
  • Loading branch information
elpete committed Sep 24, 2024
1 parent 4ce7d6d commit d3559bc
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 3 deletions.
4 changes: 2 additions & 2 deletions models/BaseEntity.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2918,8 +2918,8 @@ component accessors="true" {
var parentDefinition = getParentDefinition();

var attr = paramAttribute( { "name" : parentDefinition.joincolumn } );
variables._attributes[ attr.name ] = attr;
variables._columns[ attr.column ] = attr;
variables._attributes[ attr.name ] = variables._attributes[ attr.name ] ?: attr;
variables._columns[ attr.column ] = variables._columns[ attr.column ] ?: attr;

parentDefinition.meta.attributes
.keyArray()
Expand Down
3 changes: 2 additions & 1 deletion models/QuickBuilder.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -716,9 +716,10 @@ component accessors="true" transientCache="false" {
// Apply and append any inheritance joins/columns
if ( entity.hasParentEntity() && !entity.isSingleTableInheritance() ) {
var parentDefinition = entity.getParentDefinition();
var parentEntity = variables._wirebox.getInstance( parentDefinition.meta.fullName )
variables.qb.join(
parentDefinition.meta.table,
parentDefinition.meta.table & "." & parentDefinition.key,
parentEntity.qualifyColumn( parentDefinition.key ),
entity.qualifyColumn( entity.keyNames()[ 1 ] )
);
} else if ( entity.isDiscriminatedParent() && entity.get_loadChildren() ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
component
extends ="quick.models.BaseEntity"
table ="trip_planner_reservation_component"
discriminatorColumn="type"
accessors ="true"
{

property name="id" column="componentID";
property name="reservationId" column="reservationID";
property name="tripComponentId" column="tripComponentID";
property name="type" column="type";
property
name ="isActive"
column="isActive"
type ="boolean"
casts ="BooleanCast@quick";
property
name ="createdDate"
column="createdDate"
type ="date";
property
name ="createdByAgentId"
column="createdByAgentId"
hint ="if the record was created by an agent, the agent identifier, otherwise null";
property
name ="createdByMemberId"
column="createdByMemberId"
hint ="if the record was created by a member, the member identifier, otherwise null";
property
name ="modifiedDate"
column="modifiedDate"
type ="date";
property
name ="modifiedByAgentId"
column="modifiedByAgentId"
hint ="the agent identifier of the last agent to modify this record the record - not necessarily the most recent modification";
property
name ="modifiedByMemberId"
column="modifiedByMemberId"
hint ="the member identifier of the last member to modify this record the record - not necessarily the most recent modification";
property
name ="lastModifiedBy"
column="lastModifiedBy"
hint ="was the last person to modify this record";

variables._discriminators = [ "TripPlannerReservationComponentCruise" ];

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
component
extends ="TripPlannerReservationComponent"
table ="trip_planner_reservation_component_cruise"
joinColumn ="reservationComponentID"
discriminatorValue="cruise"
accessors ="true"
{

property name="id" column="cruiseComponentID";
property name="reservationComponentID" column="componentID";
property name="confirmationNumber" column="confirmationNumber";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
component {

function up( schema, qb ) {
schema.create( "trip_planner_reservation_component", function( table ) {
table.unsignedInteger( "componentID" );
table.unsignedInteger( "reservationID" );
table.unsignedInteger( "tripComponentID" );
table.string( "type" );
table.bit( "isActive" );
table.datetime( "createdDate" ).withCurrent();
table.unsignedInteger( "createdByAgentId" ).nullable();
table.unsignedInteger( "createdByMemberId" ).nullable();
table.datetime( "modifiedDate" ).withCurrent();
table.unsignedInteger( "modifiedByAgentId" ).nullable();
table.unsignedInteger( "modifiedByMemberId" ).nullable();
table.unsignedInteger( "lastModifiedBy" ).nullable();
} );

qb.newQuery()
.table( "trip_planner_reservation_component" )
.insert( [
{
"componentID" : 4,
"reservationID" : 5,
"tripComponentID" : 2,
"type" : "cruise",
"isActive" : 1,
"createdDate" : now(),
"modifiedDate" : now()
}
] );
}

function down( schema, qb ) {
schema.drop( "trip_planner_reservation_component" );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
component {

function up( schema, qb ) {
schema.create( "trip_planner_reservation_component_cruise", function( table ) {
table.unsignedInteger( "cruiseComponentID" );
table.unsignedInteger( "componentID" );
table.string( "confirmationNumber" );
} );

qb.newQuery()
.table( "trip_planner_reservation_component_cruise" )
.insert( [
{
"cruiseComponentID" : 11,
"componentID" : 4,
"confirmationNumber" : "ABC123"
}
] );
}

function down( schema, qb ) {
schema.drop( "trip_planner_reservation_component_cruise" );
}

}
7 changes: 7 additions & 0 deletions tests/specs/integration/BaseEntity/ChildClassSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ component extends="tests.resources.ModuleIntegrationSpec" {
"The child table row was not deleted"
);
} );

it( "can refresh a child entity", function() {
var tripComponent = getInstance( "TripPlannerReservationComponent" ).findOrFail( 4 );
expect( () => {
tripComponent.refresh();
} ).notToThrow();
} );
} );

describe( "Discriminated Class Spec", function() {
Expand Down

0 comments on commit d3559bc

Please sign in to comment.