Skip to content

Commit

Permalink
fix(memento): Correctly serialize array relationships by default
Browse files Browse the repository at this point in the history
  • Loading branch information
elpete committed Nov 7, 2019
1 parent 9d9dcdb commit 479dabc
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions models/BaseEntity.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,13 @@ component accessors="true" {
}

function loadRelationship( name ) {
var relationship = invoke( this, name );
relationship.setRelationMethodName( name );
assignRelationship( name, relationship.get() );
arguments.name = isArray( arguments.name ) ? arguments.name : [ arguments.name ];
arguments.name.each( function( n ) {
var relationship = invoke( this, n );
relationship.setRelationMethodName( n );
assignRelationship( n, relationship.get() );
} );
return this;
}

function isRelationshipLoaded( name ) {
Expand Down Expand Up @@ -995,7 +999,16 @@ component accessors="true" {
return acc;
}, {} );
var loadedRelations = variables._relationshipsData.reduce( function( acc, relationshipName, relation ) {
acc[ relationshipName ] = relation.getMemento();
if ( isArray( relation ) ) {
var mementos = relation.map( function( r ) {
return r.getMemento();
} );
// ACF 11 doesn't let use directly assign the result of map
// to a dynamic struct key. ¯\_(ツ)_/¯
acc[ relationshipName ] = mementos;
} else {
acc[ relationshipName ] = relation.getMemento();
}
return acc;
}, {} );
structAppend( data, loadedRelations );
Expand Down

0 comments on commit 479dabc

Please sign in to comment.