@@ -37,6 +37,11 @@ abstract class AbstractMapper implements Mapper
3737 */
3838 protected $ primaryKey ;
3939
40+ /**
41+ * @var string
42+ */
43+ protected $ autoIncrementKey ;
44+
4045 /**
4146 * @var Column[]
4247 */
@@ -47,11 +52,6 @@ abstract class AbstractMapper implements Mapper
4752 */
4853 private $ hydrator ;
4954
50- /**
51- * @var string
52- */
53- protected $ lastInsertIdReference ;
54-
5555 /**
5656 * @var IdentityMap
5757 */
@@ -157,9 +157,9 @@ final public function getPrimaryKey()
157157 /**
158158 * @return string
159159 */
160- final public function getLastInsertIdReference ()
160+ final public function getAutoIncrementKey ()
161161 {
162- return $ this ->lastInsertIdReference ;
162+ return $ this ->autoIncrementKey ;
163163 }
164164
165165 /**
@@ -240,9 +240,9 @@ public function isNew($dataOrEntity)
240240 public function find ($ primaryKey = [])
241241 {
242242 // load entity from cache
243- if (isset ($ primaryKey [$ this ->getLastInsertIdReference ()])){
244- if ($ this ->getIdentityMap ()->hasId ($ primaryKey [$ this ->getLastInsertIdReference ()])){
245- return $ this ->getIdentityMap ()->getObject ($ primaryKey [$ this ->getLastInsertIdReference ()]);
243+ if (isset ($ primaryKey [$ this ->getAutoIncrementKey ()])){
244+ if ($ this ->getIdentityMap ()->hasId ($ primaryKey [$ this ->getAutoIncrementKey ()])){
245+ return $ this ->getIdentityMap ()->getObject ($ primaryKey [$ this ->getAutoIncrementKey ()]);
246246 }
247247 }
248248
@@ -298,9 +298,9 @@ public function select(callable $queryCallback, $fields = ['*'], $one = false)
298298 $ entity = null ;
299299 // fetch entity from identity map
300300 // keeping object id
301- if (isset ($ record [$ this ->getLastInsertIdReference ()])){
302- if ($ identityMap ->hasId ($ record [$ this ->getLastInsertIdReference ()])){
303- $ entity = $ identityMap ->getObject ($ record [$ this ->getLastInsertIdReference ()]);
301+ if (isset ($ record [$ this ->getAutoIncrementKey ()])){
302+ if ($ identityMap ->hasId ($ record [$ this ->getAutoIncrementKey ()])){
303+ $ entity = $ identityMap ->getObject ($ record [$ this ->getAutoIncrementKey ()]);
304304 }
305305 }
306306
@@ -344,7 +344,7 @@ public function delete($entity)
344344
345345 $ result = $ query ->execute ();
346346
347- $ this ->getIdentityMap ()->remove ($ data [$ this ->getLastInsertIdReference ()], $ entity );
347+ $ this ->getIdentityMap ()->remove ($ data [$ this ->getAutoIncrementKey ()], $ entity );
348348
349349 return $ result ;
350350 }
@@ -368,12 +368,12 @@ public function create($entity)
368368 $ query ->execute ();
369369
370370 //inject auto increment key
371- if (null !== $ this ->getLastInsertIdReference ()) {
372- $ data [$ this ->getLastInsertIdReference ()] = $ this ->connection ->lastInsertId ();
371+ if (null !== $ this ->getAutoIncrementKey ()) {
372+ $ data [$ this ->getAutoIncrementKey ()] = $ this ->connection ->lastInsertId ();
373373 $ entity = $ this ->map ($ data , $ entity );
374374
375375 // add identity
376- $ this ->getIdentityMap ()->set ($ data [$ this ->getLastInsertIdReference ()], $ entity );
376+ $ this ->getIdentityMap ()->set ($ data [$ this ->getAutoIncrementKey ()], $ entity );
377377 }
378378
379379 return $ entity ;
@@ -414,7 +414,7 @@ public function update($entity)
414414 $ query ->execute ();
415415
416416 // update identity
417- $ this ->getIdentityMap ()->set ($ data [$ this ->getLastInsertIdReference ()], $ entity );
417+ $ this ->getIdentityMap ()->set ($ data [$ this ->getAutoIncrementKey ()], $ entity );
418418
419419 // we don't need to update entity data
420420 return $ entity ;
@@ -530,8 +530,8 @@ private function doDefine()
530530 reset ($ primaryKey );
531531
532532 // sanitize and validate last insert id reference which is a subset of primary key
533- if (0 < count ($ this ->primaryKey ) && null === $ this ->lastInsertIdReference ) {
534- $ this ->lastInsertIdReference = current ($ primaryKey );
533+ if (0 < count ($ this ->primaryKey ) && null === $ this ->autoIncrementKey ) {
534+ $ this ->autoIncrementKey = current ($ primaryKey );
535535 }
536536
537537 //sanitize and validate columns
0 commit comments