ソースを参照

Make Table::aliasField() idempotent.

Closes #9244
ADmad 9 年 前
コミット
4313e50416
2 ファイル変更8 行追加0 行削除
  1. 6 0
      src/ORM/Table.php
  2. 2 0
      tests/TestCase/ORM/TableTest.php

+ 6 - 0
src/ORM/Table.php

@@ -371,11 +371,17 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
     /**
      * Alias a field with the table's current alias.
      *
+     * If field is already aliased it will result in no-op.
+     *
      * @param string $field The field to alias.
      * @return string The field prefixed with the table alias.
      */
     public function aliasField($field)
     {
+        if (strpos($field, '.') !== false) {
+            return $field;
+        }
+
         return $this->alias() . '.' . $field;
     }
 

+ 2 - 0
tests/TestCase/ORM/TableTest.php

@@ -192,6 +192,8 @@ class TableTest extends TestCase
     {
         $table = new Table(['alias' => 'Users']);
         $this->assertEquals('Users.id', $table->aliasField('id'));
+
+        $this->assertEquals('Users.id', $table->aliasField('Users.id'));
     }
 
     /**