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MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;YAErF,IAAM,sBAAsB,GAAG,IAAI,CAAC,kBAAkB,CAAC,eAAe,CAAC,IAAI,CAAC,WAAY,CAAC,CAAC;YAC1F,IAAM,QAAQ,GAAG,sBAAsB,CAAC,QAAQ,CAAC,4BAA4B,CAAC,IAAI,CAAC,oBAAqB,CAAC,CAAC;YAC1G,IAAI,CAAC,QAAQ;gBACT,MAAM,IAAI,KAAK,CAAC,iCAA+B,IAAI,CAAC,oBAAoB,8BAA2B,CAAC,CAAC;YACzG,OAAO,QAAQ,CAAC;QACpB,CAAC;;;OAAA;IAKD,sBAAI,8CAAa;QAHjB;;WAEG;aACH;YACU,IAAA,oDAA8D,EAA7D,mBAAW,EAAE,wBAAgD,CAAC;YACrE,OAAO,WAAW,GAAG,GAAG,GAAG,gBAAgB,GAAG,MAAM,CAAC;QACzD,CAAC;;;OAAA;IAMD,sBAAI,iDAAgB;QAJpB;;;WAGG;aACH;YACI,OAAO,IAAI,CAAC,QAAQ,CAAC,sBAAuB,CAAC;QACjD,CAAC;;;OAAA;IAED,sBAAI,yDAAwB;aAA5B;YACI,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;QACzE,CAAC;;;OAAA;IAED,sBAAI,0DAAyB;aAA7B;YACI,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QAC1E,CAAC;;;OAAA;IAEL,0BAAC;AAAD,CAnHA,AAmHC,IAAA;AAnHY,kDAAmB","file":"RelationIdAttribute.js","sourcesContent":["import {RelationMetadata} from \"../../metadata/RelationMetadata\";\nimport {QueryBuilderUtils} from \"../QueryBuilderUtils\";\nimport {EntityMetadata} from \"../../metadata/EntityMetadata\";\nimport {QueryExpressionMap} from \"../QueryExpressionMap\";\nimport {SelectQueryBuilder} from \"../SelectQueryBuilder\";\nimport {ObjectUtils} from \"../../util/ObjectUtils\";\n\n/**\n * Stores all join relation id attributes which will be used to build a JOIN query.\n */\nexport class RelationIdAttribute {\n\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Alias of the joined (destination) table.\n */\n alias?: string;\n\n /**\n * Name of relation.\n */\n relationName: string;\n\n /**\n * Property + alias of the object where to joined data should be mapped.\n */\n mapToProperty: string;\n\n /**\n * Extra condition applied to \"ON\" section of join.\n */\n queryBuilderFactory?: (qb: SelectQueryBuilder<any>) => SelectQueryBuilder<any>;\n\n /**\n * Indicates if relation id should NOT be loaded as id map.\n */\n disableMixedMap = false;\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(private queryExpressionMap: QueryExpressionMap,\n relationIdAttribute?: Partial<RelationIdAttribute>) {\n ObjectUtils.assign(this, relationIdAttribute || {});\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n get joinInverseSideMetadata(): EntityMetadata {\n return this.relation.inverseEntityMetadata;\n }\n\n /**\n * Alias of the parent of this join.\n * For example, if we join (\"post.category\", \"categoryAlias\") then \"post\" is a parent alias.\n * This value is extracted from entityOrProperty value.\n * This is available when join was made using \"post.category\" syntax.\n */\n get parentAlias(): string {\n if (!QueryBuilderUtils.isAliasProperty(this.relationName))\n throw new Error(`Given value must be a string representation of alias property`);\n\n return this.relationName.substr(0, this.relationName.indexOf(\".\"));\n }\n\n /**\n * Relation property name of the parent.\n * This is used to understand what is joined.\n * For example, if we join (\"post.category\", \"categoryAlias\") then \"category\" is a relation property.\n * This value is extracted from entityOrProperty value.\n * This is available when join was made using \"post.category\" syntax.\n */\n get relationPropertyPath(): string {\n if (!QueryBuilderUtils.isAliasProperty(this.relationName))\n throw new Error(`Given value must be a string representation of alias property`);\n\n return this.relationName.substr(this.relationName.indexOf(\".\") + 1);\n }\n\n /**\n * Relation of the parent.\n * This is used to understand what is joined.\n * This is available when join was made using \"post.category\" syntax.\n */\n get relation(): RelationMetadata {\n if (!QueryBuilderUtils.isAliasProperty(this.relationName))\n throw new Error(`Given value must be a string representation of alias property`);\n\n const relationOwnerSelection = this.queryExpressionMap.findAliasByName(this.parentAlias!);\n const relation = relationOwnerSelection.metadata.findRelationWithPropertyPath(this.relationPropertyPath!);\n if (!relation)\n throw new Error(`Relation with property path ${this.relationPropertyPath} in entity was not found.`);\n return relation;\n }\n\n /**\n * Generates alias of junction table, whose ids we get.\n */\n get junctionAlias(): string {\n const [parentAlias, relationProperty] = this.relationName.split(\".\");\n return parentAlias + \"_\" + relationProperty + \"_rid\";\n }\n\n /**\n * Metadata of the joined entity.\n * If extra condition without entity was joined, then it will return undefined.\n */\n get junctionMetadata(): EntityMetadata {\n return this.relation.junctionEntityMetadata!;\n }\n\n get mapToPropertyParentAlias(): string {\n return this.mapToProperty.substr(0, this.mapToProperty.indexOf(\".\"));\n }\n\n get mapToPropertyPropertyPath(): string {\n return this.mapToProperty.substr(this.mapToProperty.indexOf(\".\") + 1);\n }\n\n}"],"sourceRoot":"../.."}
|