{"record":{"id":"e5872c88727cea8d","repo":"cakephp/cakephp","slug":"unknown-method-s-called-on-s","errorCode":null,"errorMessage":"Unknown method `%s` called on `%s`","messagePattern":"Unknown method `(.+?)` called on `(.+?)`","errorType":"exception","errorClass":"BadMethodCallException","httpStatus":null,"severity":"error","filePath":"src/ORM/Table.php","lineNumber":3000,"sourceCode":"     *\n     * If your Table uses any behaviors you can call them as if\n     * they were on the table object.\n     *\n     * @param string $method name of the method to be invoked\n     * @param array $args List of arguments passed to the function\n     * @return mixed\n     * @throws \\BadMethodCallException\n     */\n    public function __call(string $method, array $args): mixed\n    {\n        if ($this->_behaviors->hasMethod($method)) {\n            return $this->_behaviors->call($method, $args);\n        }\n        if (preg_match('/^find(?:\\w+)?By/', $method) > 0) {\n            return $this->_dynamicFinder($method, $args);\n        }\n\n        throw new BadMethodCallException(\n            sprintf('Unknown method `%s` called on `%s`', $method, static::class),\n        );\n    }\n\n    /**\n     * Returns the association named after the passed value if exists, otherwise\n     * throws an exception.\n     *\n     * @param string $property the association name\n     * @return \\Cake\\ORM\\Association\n     * @throws \\Cake\\Database\\Exception\\DatabaseException if no association with such name exists\n     */\n    public function __get(string $property): Association\n    {\n        $association = $this->_associations->get($property);\n        if (!$association) {\n            throw new DatabaseException(sprintf(\n                'Undefined property `%s`. ' .","sourceCodeStart":2982,"sourceCodeEnd":3018,"githubUrl":"https://github.com/cakephp/cakephp/blob/1128eba9b09f1946df684811350e26f2cef68fac/src/ORM/Table.php#L2982-L3018","documentation":"Table::__call() throws this BadMethodCallException when an undefined method is invoked on a Table instance that is neither a loaded behavior's method nor matches the findXxxByYyy() magic-finder pattern. It is the generic catch-all for typos and unsupported method names on table objects.","triggerScenarios":"Calling $table->something() that does not exist as a real method, a behavior method, or a find...By magic finder, e.g. misspelled findAllBySlug() or nonexistent deleteByUserId().","commonSituations":"Typos in method names; assuming magic methods exist for operations other than find (delete/update/count); calling a behavior method without loading the behavior; outdated IDE stubs.","solutions":["Check the spelling and existence of the method on the table class or its behaviors.","Load the behavior that provides the intended method: $this->addBehavior('Xyz').","Use explicit query builder calls (find(), updateQuery(), deleteQuery(), deleteAll()) instead of nonexistent magic methods.","Only magic finders of the form findXxxByField() are supported — rewrite other patterns accordingly."],"exampleFix":"// before\n$articles->deleteByUserId($userId); // BadMethodCallException\n// after\n$articles->deleteAll(['user_id' => $userId]);","handlingStrategy":"type-guard","validationCode":"if (!method_exists($table, $method)) {\n    // log and refuse before calling the table\n}","typeGuard":"function tableHasCallable(\\Cake\\ORM\\Table $t, string $method): bool {\n    return method_exists($t, $method) || str_contains($method, 'By');\n}","tryCatchPattern":"try {\n    $table->$method(...$args);\n} catch (\\BadMethodCallException $e) {\n    if (str_contains($e->getMessage(), 'Unknown method')) {\n        // fallback to query builder or surface error to developer\n    }\n}","preventionTips":["Rely on IDE autocomplete against the concrete table class.","Remember only findXxxByYyy() magic methods exist — not delete/update variants.","Load behaviors in initialize() before calling their methods."],"tags":["cakephp","orm","bad-method-call","undefined-method"],"backgroundTag":"method-not-implemented","analyzedSha":"1128eba9b09f1946df684811350e26f2cef68fac","analyzedAt":"2026-09-12T12:07:00.388Z","contentChangedAt":"2026-09-12T12:07:00.388Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}