diff --git a/app/Controllers/Http/PostsController.ts b/app/Controllers/Http/PostsController.ts index 0fd9f1a..9eaa25e 100755 --- a/app/Controllers/Http/PostsController.ts +++ b/app/Controllers/Http/PostsController.ts @@ -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') }) diff --git a/app/Models/Post.ts b/app/Models/Post.ts index e9f2e5b..2fac1d4 100755 --- a/app/Models/Post.ts +++ b/app/Models/Post.ts @@ -41,6 +41,14 @@ export default class Post extends BaseModel { @column() public coverId: number + @belongsTo(() => Translation, { + foreignKey: 'contentId' + }) + public content: BelongsTo + + @column() + public contentId: number + @column() public readingTime: number diff --git a/database/migrations/1629148762478_posts.ts b/database/migrations/1629148762478_posts.ts index c090c08..205be3b 100644 --- a/database/migrations/1629148762478_posts.ts +++ b/database/migrations/1629148762478_posts.ts @@ -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) }) }