Skip to content

Commit

Permalink
remove unneeded hasField check
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Nov 9, 2021
1 parent 70e8c52 commit a38bd52
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
5 changes: 0 additions & 5 deletions src/Reference/HasOneSql.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand Down
5 changes: 3 additions & 2 deletions tests/RandomTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit a38bd52

Please sign in to comment.