{"id":"258d3cbbe13ecb9d","repo":"typeorm/typeorm","slug":"cannot-find-alias-for-property-propertypath","errorCode":null,"errorMessage":"Cannot find alias for property ${propertyPath}","messagePattern":"Cannot find alias for property (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/query-builder/QueryBuilder.ts","lineNumber":1386,"sourceCode":"                if (!joinAttr?.alias) {\n                    const fullRelationPath =\n                        root.length > 0 ? `${root.join(\".\")}.${part}` : part\n                    throw new Error(\n                        `Cannot find alias for relation at ${fullRelationPath}`,\n                    )\n                }\n\n                alias = joinAttr.alias\n                root.push(...part.split(\".\"))\n                propertyPathParts.shift()\n                continue\n            }\n\n            break\n        }\n\n        if (!alias) {\n            throw new Error(`Cannot find alias for property ${propertyPath}`)\n        }\n\n        // Remaining parts are combined back and used to find the actual property path\n        const aliasPropertyPath = propertyPathParts.join(\".\")\n\n        const columns =\n            alias.metadata.findColumnsWithPropertyPath(aliasPropertyPath)\n\n        if (!columns.length) {\n            throw new EntityPropertyNotFoundError(propertyPath, alias.metadata)\n        }\n\n        return [alias, root, columns]\n    }\n\n    /**\n     * Creates a property paths for a given ObjectLiteral.\n     *","sourceCodeStart":1368,"sourceCodeEnd":1404,"githubUrl":"https://github.com/typeorm/typeorm/blob/04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96/src/query-builder/QueryBuilder.ts#L1368-L1404","documentation":"Fallback thrown by findColumnsForPropertyPath when, after walking the property path, alias is still undefined. This generally means the main alias has no metadata (no entity bound) so the relation/embedded lookups were skipped, leaving no resolvable alias. It is the terminal case when no alias could be associated with the property.","triggerScenarios":"You build a query builder from a raw table or subquery string (no entity metadata), e.g. createQueryBuilder().select(...).where({ 'some.column': 1 }), then reference a dotted property path. The main alias lacks metadata so the loop breaks immediately and alias stays undefined.","commonSituations":"Using createQueryBuilder with a raw table name instead of an entity. Calling where/addMapping on a query whose FROM is a subquery. Mixing entity-style property paths with raw-table builders.","solutions":["Bind an entity as the main alias: createQueryBuilder(Entity, 'alias') so metadata is available for property-path resolution.","If querying a raw table, use raw SQL fragments in where (e.g. 'table.column = :val') instead of property-path object keys.","Ensure the FROM clause resolves to entity metadata, not a subquery string."],"exampleFix":"// before\nconst qb = dataSource.createQueryBuilder()\n  .from('users', 'u')\n  .where({ 'profile.city': 'NYC' }); // 484: no metadata\n\n// after\nconst qb = dataSource.createQueryBuilder(User, 'u')\n  .leftJoin('u.profile', 'profile')\n  .where('profile.city = :city', { city: 'NYC' });","handlingStrategy":"validation","validationCode":"function assertHasEntityMainAlias(qb) {\n  const a = qb.expressionMap.mainAlias;\n  if (!a || !a.hasMetadata) throw new Error('QueryBuilder needs an entity main alias for property paths');\n}","typeGuard":"function hasEntityMainAlias(qb): boolean {\n  const a = qb.expressionMap.mainAlias;\n  return !!a && !!a.hasMetadata;\n}","tryCatchPattern":null,"preventionTips":["Start builders from an entity: createQueryBuilder(Entity, 'alias').","Use raw SQL where() fragments for raw-table queries instead of property-path keys.","Avoid mixing raw FROM with entity-style property paths."],"tags":["alias","property-path","metadata","query-builder"],"analyzedSha":"04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96","analyzedAt":"2026-08-03T18:27:32.281Z","schemaVersion":2}