@@ -706,6 +706,23 @@ addHiddenPropsToTarget(Adapter.prototype, {
706706 return def . getForeignKey ( record )
707707 } ,
708708
709+ /**
710+ * Return the localKeys from the given record for the provided relationship.
711+ *
712+ * Override with care.
713+ *
714+ * @name Adapter#makeHasManyLocalKeys
715+ * @method
716+ * @return {* }
717+ */
718+ makeHasManyLocalKeys ( mapper , def , record ) {
719+ let localKeys = [ ]
720+ let itemKeys = get ( record , def . localKeys ) || [ ]
721+ itemKeys = isArray ( itemKeys ) ? itemKeys : Object . keys ( itemKeys )
722+ localKeys = localKeys . concat ( itemKeys )
723+ return unique ( localKeys ) . filter ( function ( x ) { return x } )
724+ } ,
725+
709726 /**
710727 * Return the foreignKeys from the given record for the provided relationship.
711728 *
@@ -779,25 +796,19 @@ addHiddenPropsToTarget(Adapter.prototype, {
779796 }
780797
781798 if ( record ) {
782- let localKeys = [ ]
783- let itemKeys = get ( record , def . localKeys ) || [ ]
784- itemKeys = isArray ( itemKeys ) ? itemKeys : Object . keys ( itemKeys )
785- localKeys = localKeys . concat ( itemKeys )
786799 return self . findAll ( relatedMapper , {
787800 where : {
788801 [ relatedMapper . idAttribute ] : {
789- 'in' : unique ( localKeys ) . filter ( function ( x ) { return x } )
802+ 'in' : self . makeHasManyLocalKeys ( mapper , def , record )
790803 }
791804 }
792805 } , __opts ) . then ( function ( relatedItems ) {
793806 def . setLocalField ( record , relatedItems )
794807 } )
795808 } else {
796809 let localKeys = [ ]
797- records . forEach ( function ( item ) {
798- let itemKeys = item [ def . localKeys ] || [ ]
799- itemKeys = isArray ( itemKeys ) ? itemKeys : Object . keys ( itemKeys )
800- localKeys = localKeys . concat ( itemKeys )
810+ records . forEach ( function ( record ) {
811+ localKeys = localKeys . concat ( self . self . makeHasManyLocalKeys ( mapper , def , record ) )
801812 } )
802813 return self . findAll ( relatedMapper , {
803814 where : {
0 commit comments