Skip to content

Commit

Permalink
fix(HasOneThrough): Add missing matchOne method
Browse files Browse the repository at this point in the history
  • Loading branch information
elpete committed Sep 24, 2024
1 parent d3559bc commit a09196e
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion models/Relationships/BelongsToThrough.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,44 @@ component extends="quick.models.Relationships.BaseRelationship" {
required array results,
required string relation
) {
return matchOne( argumentCollection = arguments );
var dictionary = buildDictionary( arguments.results );
arguments.entities.each( function( entity ) {
var key = variables.localKeys
.map( function( localKey ) {
return structKeyExists( entity, "isQuickEntity" ) ? entity.retrieveAttribute( localKey ) : entity[
localKey
];
} )
.toList();
if ( structKeyExists( dictionary, key ) ) {
if ( structKeyExists( arguments.entity, "isQuickEntity" ) ) {
arguments.entity.assignRelationship( relation, getRelationValue( dictionary, key, "one" ) );
} else {
arguments.entity[ relation ] = getRelationValue( dictionary, key, "one" );
}
}
} );
return arguments.entities;
}

/**
* Retrieves the value for the key from the dictionary.
* Also, returns either the first result for a "one" type or the entire
* array of results for a "many" type.
*
* @dictionary A dictionary mapping the `foreignKey` value to related results.
* @key The `foreignKey` value to look up in the dictionary.
* @type The type of the relation value, "many" or "one".
*
* @return quick.models.BaseEntity | [quick.models.BaseEntity]
*/
public any function getRelationValue(
required struct dictionary,
required string key,
required string type
) {
var value = arguments.dictionary[ arguments.key ];
return arguments.type == "one" ? value[ 1 ] : value;
}

/**
Expand Down

0 comments on commit a09196e

Please sign in to comment.