fix: viewName set

This commit is contained in:
Chareice 2023-04-03 21:02:41 +08:00
parent 9f16eae936
commit 7cf96eefb6
2 changed files with 9 additions and 0 deletions

View File

@ -65,6 +65,8 @@ describe('view collection', function () {
const otherSchemaView = db.getCollection(`${randomSchema}_${viewName}`); const otherSchemaView = db.getCollection(`${randomSchema}_${viewName}`);
expect(otherSchemaView).toBeInstanceOf(ViewCollection); expect(otherSchemaView).toBeInstanceOf(ViewCollection);
expect(otherSchemaView.options.viewName).toBe(viewName);
expect(otherSchemaView.options.schema).toBe(randomSchema);
}); });
it('should support view with dot field', async () => { it('should support view with dot field', async () => {

View File

@ -15,6 +15,13 @@ export function beforeCreateForViewCollection(db: Database) {
if (exists) { if (exists) {
const prefix = model.get('schema') || 'public'; const prefix = model.get('schema') || 'public';
const viewName = `${prefix}_${name}`; const viewName = `${prefix}_${name}`;
// set collection viewName
if (!model.get('viewName')) {
model.set('viewName', name);
}
// set collection name
model.set('name', viewName); model.set('name', viewName);
} }
}; };