Commit 80a1f2a9 authored by William Naslund's avatar William Naslund

Fixed lookup field being added to table fields multiple times in different databases.

parent 9912635c
......@@ -43,11 +43,21 @@ export function getTableFields(modelType: DBModelConstructor<any>): DBFieldInfor
throw new Error(`The lookup "${parentLookup.name}" on ${modelType} looks up to a model with an id "${String(parentInfo.options.id)}" that has no registered field inofrmation`);
}
fields.push({
name: parentLookup.name,
propertyKey: parentLookup.propertyKey,
type: parentIdInfo.type.lookupType ? parentIdInfo.type.lookupType() : parentIdInfo.type
});
let hasLookupField = false;
for(const field of fields) {
if(field.name == parentLookup.name) {
hasLookupField = true;
break;
}
}
if(!hasLookupField) {
fields.push({
name: parentLookup.name,
propertyKey: parentLookup.propertyKey,
type: parentIdInfo.type.lookupType ? parentIdInfo.type.lookupType() : parentIdInfo.type
});
}
}
return fields;
......
......@@ -4,15 +4,31 @@ import { Database } from "@swirl/db";
import { Contact } from "./db/contact";
describe('migrate()', function() {
let db = new Database(TEST_ADAPTER);
let db: Database;
afterEach(async () => {
// await db.delete();
await db.close();
beforeEach(async () => {
db = new Database(TEST_ADAPTER);
});
it('Creates the schema', async () => {
it('Creates the schema for a brand new database', async () => {
await db.register(Account).register(Contact).migrate();
});
it('Does not change anything when updating the existing schema', async () => {
await db.register(Account).register(Contact).migrate();
await db.migrate();
});
it('Testing 123', async function() {
});
afterEach(async () => {
await db.delete();
});
after(async () => {
await db.close();
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment