From a38bd5286de1b1927774e85e9bb24a685e8eea1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Tue, 9 Nov 2021 18:36:41 +0100 Subject: [PATCH] remove unneeded hasField check --- src/Reference/HasOneSql.php | 5 ----- tests/RandomTest.php | 5 +++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Reference/HasOneSql.php b/src/Reference/HasOneSql.php index e5515887a..914c69fef 100644 --- a/src/Reference/HasOneSql.php +++ b/src/Reference/HasOneSql.php @@ -175,11 +175,6 @@ public function addTitle(array $defaults = []): FieldSqlExpression $fieldName = $defaults['field'] ?? preg_replace('~_(' . preg_quote($ourModel->id_field, '~') . '|id)$~', '', $this->link); - if ($ourModel->hasField($fieldName)) { - throw (new Exception('Field with this name already exists. Please set title field name manually addTitle([\'field\' => \'field_name\'])')) - ->addMoreInfo('field', $fieldName); - } - /** @var FieldSqlExpression $fieldExpression */ $fieldExpression = $ourModel->addExpression($fieldName, array_replace_recursive( [ diff --git a/tests/RandomTest.php b/tests/RandomTest.php index 2d6e9d532..efaaa14bf 100644 --- a/tests/RandomTest.php +++ b/tests/RandomTest.php @@ -4,6 +4,7 @@ namespace Atk4\Data\Tests; +use Atk4\Core\Exception as CoreException; use Atk4\Data\Exception; use Atk4\Data\Model; use Atk4\Data\Persistence; @@ -255,7 +256,7 @@ public function testUpdateCondition(): void // we can use afterUpdate to make sure that record was updated if (!$st->rowCount()) { - throw (new \Atk4\Core\Exception('Update didn\'t affect any records')) + throw (new Exception('Update didn\'t affect any records')) ->addMoreInfo('query', $update->getDebugQuery()) ->addMoreInfo('statement', $st) ->addMoreInfo('model', $m); @@ -327,7 +328,7 @@ public function testIssue220(): void $db = new Persistence\Sql($this->db->connection); $m = new Model_Item($db); - $this->expectException(Exception::class); + $this->expectException(CoreException::class); $m->hasOne('foo', ['model' => [Model_Item::class]]) ->addTitle(); // field foo already exists, so we can't add title with same name }