fix: relations media links with models.

This commit is contained in:
Ahmed Bouhuolia
2020-10-08 00:00:49 +02:00
parent 15dca0a7d2
commit 8df5a45c29
3 changed files with 7 additions and 1 deletions

View File

@@ -3,7 +3,7 @@ exports.up = function(knex) {
return knex.schema.createTable('media_links', table => {
table.increments();
table.string('model_name').index();
table.integer('media_id').unsigned().index();
table.integer('media_id').unsigned().references('id').inTable('media');
table.integer('model_id').unsigned().index();
})
};

View File

@@ -103,6 +103,9 @@ export default class Expense extends TenantModel {
},
to: 'media.id',
},
filter(query) {
query.where('model_name', 'Expense');
}
},
};
}

View File

@@ -46,6 +46,9 @@ export default class ManualJournal extends TenantModel {
to: 'media_links.media_id',
},
to: 'media.id',
},
filter(query) {
query.where('model_name', 'ManualJournal');
}
}
};