Browse Source

Merge pull request #13263 from cakephp/issue-13256

Improve error message for missing associations.
Mark Story 6 years ago
parent
commit
e67bb6c657
2 changed files with 6 additions and 4 deletions
  1. 5 3
      src/ORM/Table.php
  2. 1 1
      tests/TestCase/ORM/AssociationProxyTest.php

+ 5 - 3
src/ORM/Table.php

@@ -2531,9 +2531,11 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
         $association = $this->_associations->get($property);
         if (!$association) {
             throw new RuntimeException(sprintf(
-                'Table "%s" is not associated with "%s"',
-                get_class($this),
-                $property
+                'Undefined property `%s`. ' .
+                'You have not defined the `%s` association on `%s`.',
+                $property,
+                $property,
+                static::class
             ));
         }
 

+ 1 - 1
tests/TestCase/ORM/AssociationProxyTest.php

@@ -68,7 +68,7 @@ class AssociationProxyTest extends TestCase
     public function testGetBadAssociation()
     {
         $this->expectException(\RuntimeException::class);
-        $this->expectExceptionMessage('Table "Cake\ORM\Table" is not associated with "posts"');
+        $this->expectExceptionMessage('You have not defined');
         $articles = $this->getTableLocator()->get('articles');
         $articles->posts;
     }