herbs-cli icon indicating copy to clipboard operation
herbs-cli copied to clipboard

herbs update - Entities with relationship

Open dalssoft opened this issue 3 years ago • 1 comments

Would be great if we improve the behavior of herbs update for cases when entities have relationship with other entities.

one-to-one

    entity('ToDoList', {
        id: field(Number),
        items: field(Item),

This should create a migration with:

            return knex.schema
                .createTable('ToDoList', function (table) {
                    table.string('id').primary()
                    table.string('itemId').references('id').inTable('Item')
                })

one-to-many

    entity('ToDoList', {
        id: field(Number),
        items: field([Item]),

This should create a migration with:

            return knex.schema
                .createTable('ToDoList', function (table) {
                    table.string('id').primary()
                    ...
                })

                .alterTable('Item', function (table) {
                    table.string('itemId').references('id').inTable('ToDoList')
                    ...
                })

dalssoft avatar Jul 05 '22 14:07 dalssoft

@endersoncosta is working on it PR: https://github.com/herbsjs/herbs-cli/pull/144

dalssoft avatar Jul 05 '22 23:07 dalssoft