Repository: typeorm/typeorm
File: src/metadata-builder/EntityMetadataBuilder.ts (TypeScript)

Code before:
                            junctionEntityMetadata.ownIndices[0].columns,
                            junctionEntityMetadata.ownIndices[1].columns,
                        )
                        relation.registerJunctionEntityMetadata(
                            junctionEntityMetadata,
                        )

                        // compute new entity metadata properties and push it to entity metadatas pool
                        this.computeEntityMetadataStep2(junctionEntityMetadata)
                        this.computeInverseProperties(
                            junctionEntityMetadata,
                            entityMetadatas,
                        )

                        // check if there's already a user-defined entity with the same table name
                        // if so, don't add the auto-generated junction entity to avoid duplicates
                        const existingEntity = entityMetadatas.find(
                            (metadata) =>
                                metadata.tableName ===
                                    junctionEntityMetadata.tableName &&
                                !metadata.isJunction,
                        )

                        if (!existingEntity) {
                            entityMetadatas.push(junctionEntityMetadata)
                        }
                    })
            })

        // update entity metadata depend properties
        entityMetadatas.forEach((entityMetadata) => {
            entityMetadata.relationsWithJoinColumns =
                entityMetadata.relations.filter(
                    (relation) => relation.isWithJoinColumn,
                )
            entityMetadata.hasNonNullableRelations =
                entityMetadata.relationsWithJoinColumns.some(
                    (relation) => !relation.isNullable || relation.isPrimary,
                )
        })

        // generate closure junction tables for all closure tables
        entityMetadatas
            .filter((metadata) => metadata.treeType === "closure-table")
            .forEach((entityMetadata) => {
                const closureJunctionEntityMetadata =
                    this.closureJunctionEntityMetadataBuilder.build(
                        entityMetadata,
                    )
                entityMetadata.closureJunctionTable =
                    closureJunctionEntityMetadata

Review comment (suggestion):
Prefer using `Array.some` instead of `Array.find` when you just want a boolean:

```suggestion
                        const hasUserDefinedTable = entityMetadatas.some(
                            (metadata) =>
                                metadata.tableName ===
                                    junctionEntityMetadata.tableName &&
                                !metadata.isJunction,
                        )

                        if (!hasUserDefinedTable) {
                            entityMetadatas.push(junctionEntityMetadata)
                        }
```

Code after:
                            junctionEntityMetadata.ownIndices[0].columns,
                            junctionEntityMetadata.ownIndices[1].columns,
                        )
                        relation.registerJunctionEntityMetadata(
                            junctionEntityMetadata,
                        )

                        // compute new entity metadata properties and push it to entity metadatas pool
                        this.computeEntityMetadataStep2(junctionEntityMetadata)
                        this.computeInverseProperties(
                            junctionEntityMetadata,
                            entityMetadatas,
                        )

                        // check if there's already a user-defined entity with the same table name
                        // if so, don't add the auto-generated junction entity to avoid duplicates
                        const hasUserDefinedTable = entityMetadatas.some(
                            (metadata) =>
                                metadata.tableName ===
                                    junctionEntityMetadata.tableName &&
                                !metadata.isJunction,
                        )

                        if (!hasUserDefinedTable) {
                            entityMetadatas.push(junctionEntityMetadata)
                        }
                    })
            })

        // update entity metadata depend properties
        entityMetadatas.forEach((entityMetadata) => {
            entityMetadata.relationsWithJoinColumns =
                entityMetadata.relations.filter(
                    (relation) => relation.isWithJoinColumn,
                )
            entityMetadata.hasNonNullableRelations =
                entityMetadata.relationsWithJoinColumns.some(
                    (relation) => !relation.isNullable || relation.isPrimary,
                )
        })

        // generate closure junction tables for all closure tables
        entityMetadatas
            .filter((metadata) => metadata.treeType === "closure-table")
            .forEach((entityMetadata) => {
                const closureJunctionEntityMetadata =
                    this.closureJunctionEntityMetadataBuilder.build(
                        entityMetadata,
                    )
                entityMetadata.closureJunctionTable =
                    closureJunctionEntityMetadata