Skip to content

[Bug] Change assoc many slice and Update/Insert with Changeset #308

Description

@qRoC

Append

Example

type Main struct {
    ID        int `db:",primary"`
    Childs []*Child `ref:"id" fk:"main_id" autosave:"true" autoload:"true"`
}

type Child struct {
    ID        int `db:",primary"`
    MainID int
    Name string
}

main := new(Main)
repo.Find(ctx, main, rel.Eq("id", id))
changeset := rel.NewChangeset(main)
main.Childs = append(main.Childs, &Child{...})
repo.Update(ctx, main, changeset)

Actual result

panic("rel: invalid mutator")

Change

Example

main := new(Main)
repo.Find(ctx, main, rel.Eq("id", id))
changeset := rel.NewChangeset(main)
main.Childs[0].Name = "foo"
main.Childs[1].Name = "bar"
repo.Update(ctx, main, changeset)

Actual result

generate invalid queries

DELETE FROM "child" WHERE "child"."main_id"=$1;
INSERT INTO "child" ("name","main_id") VALUES ($1,$2),($3,$4) RETURNING "id"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions