PR comments.
This commit is contained in:
parent
9e8a855d14
commit
4ab3aef020
|
@ -24,9 +24,11 @@ export function isManyToMany(
|
||||||
|
|
||||||
function isCorrectRelationship(
|
function isCorrectRelationship(
|
||||||
relationship: RelationshipsJson,
|
relationship: RelationshipsJson,
|
||||||
|
table1: Table,
|
||||||
|
table2: Table,
|
||||||
row: Row
|
row: Row
|
||||||
): boolean {
|
): boolean {
|
||||||
const junctionTableId = relationship.through!
|
const junctionTableId = generateJunctionTableID(table1._id!, table2._id!)
|
||||||
const possibleColumns = [
|
const possibleColumns = [
|
||||||
`${junctionTableId}.doc1.fieldName`,
|
`${junctionTableId}.doc1.fieldName`,
|
||||||
`${junctionTableId}.doc2.fieldName`,
|
`${junctionTableId}.doc2.fieldName`,
|
||||||
|
@ -76,7 +78,10 @@ export async function updateRelationshipColumns(
|
||||||
if (!linked._id) {
|
if (!linked._id) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (!opts?.sqs || isCorrectRelationship(relationship, row)) {
|
if (
|
||||||
|
!opts?.sqs ||
|
||||||
|
isCorrectRelationship(relationship, table, linkedTable, row)
|
||||||
|
) {
|
||||||
columns[relationship.column] = linked
|
columns[relationship.column] = linked
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2085,7 +2085,6 @@ describe.each([
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
isInternal &&
|
|
||||||
describe("relations to same table", () => {
|
describe("relations to same table", () => {
|
||||||
let relatedTable: Table, relatedRows: Row[]
|
let relatedTable: Table, relatedRows: Row[]
|
||||||
|
|
||||||
|
@ -2116,12 +2115,21 @@ describe.each([
|
||||||
relatedRows = await Promise.all([
|
relatedRows = await Promise.all([
|
||||||
config.api.row.save(relatedTable._id!, { name: "foo" }),
|
config.api.row.save(relatedTable._id!, { name: "foo" }),
|
||||||
config.api.row.save(relatedTable._id!, { name: "bar" }),
|
config.api.row.save(relatedTable._id!, { name: "bar" }),
|
||||||
|
config.api.row.save(relatedTable._id!, { name: "baz" }),
|
||||||
|
config.api.row.save(relatedTable._id!, { name: "boo" }),
|
||||||
])
|
])
|
||||||
await config.api.row.save(table._id!, {
|
await Promise.all([
|
||||||
|
config.api.row.save(table._id!, {
|
||||||
name: "test",
|
name: "test",
|
||||||
related1: [relatedRows[0]._id!],
|
related1: [relatedRows[0]._id!],
|
||||||
related2: [relatedRows[1]._id!],
|
related2: [relatedRows[1]._id!],
|
||||||
})
|
}),
|
||||||
|
config.api.row.save(table._id!, {
|
||||||
|
name: "test2",
|
||||||
|
related1: [relatedRows[2]._id!],
|
||||||
|
related2: [relatedRows[3]._id!],
|
||||||
|
}),
|
||||||
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should be able to relate to same table", async () => {
|
it("should be able to relate to same table", async () => {
|
||||||
|
@ -2133,6 +2141,45 @@ describe.each([
|
||||||
related1: [{ _id: relatedRows[0]._id }],
|
related1: [{ _id: relatedRows[0]._id }],
|
||||||
related2: [{ _id: relatedRows[1]._id }],
|
related2: [{ _id: relatedRows[1]._id }],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "test2",
|
||||||
|
related1: [{ _id: relatedRows[2]._id }],
|
||||||
|
related2: [{ _id: relatedRows[3]._id }],
|
||||||
|
},
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
isSqs &&
|
||||||
|
it("should be able to filter down to second row with equal", async () => {
|
||||||
|
await expectSearch({
|
||||||
|
query: {
|
||||||
|
equal: {
|
||||||
|
["related1.name"]: "baz",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}).toContainExactly([
|
||||||
|
{
|
||||||
|
name: "test2",
|
||||||
|
related1: [{ _id: relatedRows[2]._id }],
|
||||||
|
},
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
isSqs &&
|
||||||
|
it("should be able to filter down to first row with not equal", async () => {
|
||||||
|
await expectSearch({
|
||||||
|
query: {
|
||||||
|
notEqual: {
|
||||||
|
["1:related2.name"]: "bar",
|
||||||
|
["2:related2.name"]: "baz",
|
||||||
|
["3:related2.name"]: "boo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}).toContainExactly([
|
||||||
|
{
|
||||||
|
name: "test",
|
||||||
|
related1: [{ _id: relatedRows[0]._id }],
|
||||||
|
},
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -176,12 +176,10 @@ export async function addTable(table: Table) {
|
||||||
export async function removeTable(table: Table) {
|
export async function removeTable(table: Table) {
|
||||||
const db = context.getAppDB()
|
const db = context.getAppDB()
|
||||||
try {
|
try {
|
||||||
let response = await Promise.all([
|
const [tables, definition] = await Promise.all([
|
||||||
tablesSdk.getAllInternalTables(),
|
tablesSdk.getAllInternalTables(),
|
||||||
db.get<SQLiteDefinition>(SQLITE_DESIGN_DOC_ID),
|
db.get<SQLiteDefinition>(SQLITE_DESIGN_DOC_ID),
|
||||||
])
|
])
|
||||||
const tables: Table[] = response[0],
|
|
||||||
definition: SQLiteDefinition = response[1]
|
|
||||||
const tableIds = tables
|
const tableIds = tables
|
||||||
.map(tbl => tbl._id!)
|
.map(tbl => tbl._id!)
|
||||||
.filter(id => !id.includes(table._id!))
|
.filter(id => !id.includes(table._id!))
|
||||||
|
|
Loading…
Reference in New Issue