Add post content

This commit is contained in:
2021-08-28 19:08:48 +02:00
parent 5a2d1fab43
commit 48552f0ccf
3 changed files with 14 additions and 0 deletions

View File

@@ -10,6 +10,7 @@ export default class PostsController {
public async index ({ response }: HttpContextContract) {
return response.status(200).send({
posts: await Post.query()
.orderBy('id', 'desc')
.preload('tags', (tags) => {
tags.preload('label')
})

View File

@@ -41,6 +41,14 @@ export default class Post extends BaseModel {
@column()
public coverId: number
@belongsTo(() => Translation, {
foreignKey: 'contentId'
})
public content: BelongsTo<typeof Translation>
@column()
public contentId: number
@column()
public readingTime: number

View File

@@ -25,6 +25,11 @@ export default class Posts extends BaseSchema {
.unsigned()
.references('files.id')
.onDelete('CASCADE')
table
.integer('content_id')
.unsigned()
.references('translations.id')
.onDelete('CASCADE')
table.timestamps(true, true)
})
}