Skip to content

Commit

Permalink
Improving the error message for associations with no PK.
Browse files Browse the repository at this point in the history
This makes it more clear what needs to be done to fix the issue.
  • Loading branch information
Florian Krämer committed Jun 13, 2016
1 parent 376fc96 commit 74e3968
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ORM/Association.php
Expand Up @@ -841,6 +841,11 @@ protected function _joinCondition($options)
$bindingKey = (array)$this->bindingKey();

if (count($foreignKey) !== count($bindingKey)) {
if (empty($bindingKey)) {
$msg = 'The "%s" table does not define a primary key. Please set one.';
throw new RuntimeException(sprintf($msg, $this->target()->table()));
}

$msg = 'Cannot match provided foreignKey for "%s", got "(%s)" but expected foreign key for "(%s)"';
throw new RuntimeException(sprintf(
$msg,
Expand Down
5 changes: 5 additions & 0 deletions src/ORM/Association/BelongsTo.php
Expand Up @@ -157,6 +157,11 @@ protected function _joinCondition($options)
$bindingKey = (array)$this->bindingKey();

if (count($foreignKey) !== count($bindingKey)) {
if (empty($bindingKey)) {
$msg = 'The "%s" table does not define a primary key. Please set one.';
throw new RuntimeException(sprintf($msg, $this->target()->table()));
}

$msg = 'Cannot match provided foreignKey for "%s", got "(%s)" but expected foreign key for "(%s)"';
throw new RuntimeException(sprintf(
$msg,
Expand Down

0 comments on commit 74e3968

Please sign in to comment.