go-rel / go-rel/rel

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

Open
#308 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
786
Forks
61
Avg merge
4d 11h
Merged PRs (30d)
2

Description

## Append

**Example**

```go
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**

```go
panic("rel: invalid mutator")
```

## Change

**Example**

```go
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

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.