{"record":{"id":"8c3f2a4a8ae516dc","repo":"phalcon/cphalcon","slug":"eager-loading-does-not-support-the-limit-option","errorCode":null,"errorMessage":"Eager loading does not support the 'limit' option: a per-parent limit requires a window function, which PHQL cannot express","messagePattern":"Eager loading does not support the 'limit' option: a per-parent limit requires a window function, which PHQL cannot express","errorType":"exception","errorClass":"Phalcon\\Mvc\\Model\\Exceptions\\UnsupportedEagerOption","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/Model/Eager/PathTree.zep","lineNumber":87,"sourceCode":"                throw new InvalidEagerPath(path);\n            }\n\n            let tree = self::insert(tree, path, segments, 0, options);\n        }\n\n        return tree;\n    }\n\n    /**\n     * A per-parent limit requires ROW_NUMBER() OVER (PARTITION BY ...), which\n     * PHQL has no syntax for. Applying `limit` to the batch query instead\n     * would return N children in total rather than N per parent, which is\n     * silently wrong.\n     */\n    private static function assertOptions(array options) -> void\n    {\n        if unlikely isset options[\"limit\"] {\n            throw new UnsupportedEagerOption(\"limit\");\n        }\n\n        if unlikely isset options[\"offset\"] {\n            throw new UnsupportedEagerOption(\"offset\");\n        }\n    }\n\n    /**\n     * @param array  $tree     accumulated tree\n     * @param string $path     the original path, for error messages\n     * @param array  $segments exploded path\n     * @param int    $index    segment currently being inserted\n     * @param array  $options  attach to the last segment only\n     */\n    private static function insert(\n        array tree,\n        string path,\n        array segments,","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Model/Eager/PathTree.zep#L69-L105","documentation":"Thrown by PathTree::assertOptions() when an option map for an eager path contains 'limit'. PHQL cannot express ROW_NUMBER() OVER (PARTITION BY ...), so a per-parent limit cannot be implemented; applying a global limit to the batch query would silently return N rows total instead of N per parent, so the option is rejected outright.","triggerScenarios":"Thrown at phalcon/Mvc/Model/Eager/PathTree.zep:87 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove the 'limit' option from the eager path and enforce per-parent limits in application code after hydration","Post-process the loaded relation and keep only the first N children per parent","Use a native SQL query with a window function if a true per-parent limit is required"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","contentChangedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}