En mi backend basado en NodeJS, KnexJS, PSQL, tengo un problema con un filtro cuando se solicita de 2 tablas obtener datos usando 2 columnas que tienen el mismo nombre.
El problema pertenece a esta parte de la consulta y en el específico cuando se solicita al mismo tiempo: authorTypes y conversationOriginTypes
El error de PSQL:
column reference "origin_type" is ambiguous if (!isEmpty(authorTypes) || !isEmpty(authorIds)) { this.builder.join( memberTable, `${memberTable}.${memberColumns.id}`, `${tableName}.${columns.memberId}` ); if (!isEmpty(authorTypes)) { this.builder.whereIn(memberColumns.memberType, authorTypes); } if (!isEmpty(authorIds)) { this.builder.whereIn(memberColumns.memberId, authorIds); } } if (!isEmpty(conversationOriginTypes) || !isEmpty(conversationOriginIds)) { this.builder.join( conversationTable, `${conversationTable}.${conversationColumns.id}`, `${tableName}.${columns.conversationId}` ); if (!isEmpty(conversationOriginTypes)) { this.builder.whereIn( conversationColumns.originType, conversationOriginTypes ); } if (!isEmpty(conversationOriginIds)) { this.builder.whereIn( conversationColumns.originId, conversationOriginIds ); } }Ambas tablas tienen la siguiente estructura:
// CONVERSATION TABLE export const conversationTable = 'conversation'; export const conversationColumns = { id: 'id', topic: 'topic', originType: 'origin_type', -> here the issue! originId: 'origin_id', createdAt: 'created_at', }; // MEMBER TABLE export const memberTable = 'member'; export const memberColumns = { id: 'id', name: 'name', memberType: 'origin_type', -> here the issue! memberId: 'origin_id', createdAt: 'created_at', };No sé cómo modificar esa parte que compartí para evitar este problema. Me preguntaba si necesito alias de alguna manera, pero probé algunos ejemplos en línea pero obtuve el mismo error, así que probablemente lo esté haciendo mal.