@@ -494,11 +494,12 @@ private function commandWhere($cond)
494494 $ replacePlaceholders = TRUE ;
495495 $ field = &$ args [0 ];
496496 list (, $ field , $ operator ) = $ matches ;
497- $ value = $ args [1 ];
497+ $ value = & $ args [1 ];
498498
499499 $ placeholder = self ::$ defaultPlaceholder ;
500500 if (!$ operator ) {
501501 if (is_array ($ value )) {
502+ $ value = $ this ->replaceEntitiesForItsPrimaryKeyValues ($ value );
502503 $ operator = 'IN ' ;
503504 $ placeholder = '%in ' ;
504505 } elseif ($ value === NULL ) {
@@ -516,18 +517,24 @@ private function commandWhere($cond)
516517 $ statement = &$ args [0 ];
517518 $ statement = $ this ->parseStatement ($ statement , $ replacePlaceholders );
518519 $ statement = "( $ statement) " ;
519- // Replace instances of Entity for its values.
520- foreach ($ args as &$ arg ) {
521- if ($ arg instanceof LeanMapper \Entity) {
522- $ entityTable = $ this ->mapper ->getTable (get_class ($ arg ));
523- $ idField = $ this ->mapper ->getEntityField ($ entityTable , $ this ->mapper ->getPrimaryKey ($ entityTable ));
524- $ arg = $ arg ->$ idField ;
525- }
526- }
520+ $ args = $ this ->replaceEntitiesForItsPrimaryKeyValues ($ args );
527521 call_user_func_array (array ($ this ->fluent , 'where ' ), $ args );
528522 }
529523 }
530524
525+ private function replaceEntitiesForItsPrimaryKeyValues (array $ entities )
526+ {
527+ foreach ($ entities as &$ entity ) {
528+ if ($ entity instanceof LeanMapper \Entity) {
529+ $ entityTable = $ this ->mapper ->getTable (get_class ($ entity ));
530+ // FIXME: Column name could be specified in the entity instead of mapper provided by 'getEntityField' function.
531+ $ idField = $ this ->mapper ->getEntityField ($ entityTable , $ this ->mapper ->getPrimaryKey ($ entityTable ));
532+ $ entity = $ entity ->$ idField ;
533+ }
534+ }
535+ return $ entities ;
536+ }
537+
531538 private function commandOrderBy ($ field )
532539 {
533540 if (is_array ($ field )) {
0 commit comments