go-rel / go-rel/rel

Persist structures with no data fields besides id

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

Description

I have a mapping like this:

```
type Product struct {
Id int
PropertyGroup PropertyGroup `ref:"property_group_id" fk:"id" autosave:"true" autoload:"true"`
PropertyGroupId int
}

type PropertyGroup struct {
Id int
Properties []Property `ref:"id" fk:"group_id" autosave:"true" autoload:"true"`
}

type Property struct {
Id int
Key string
Value string

Group PropertyGroup `ref:"group_id" fk:"id"`
GroupId int
}
```

Please note that what's important here is the PropertyGroup, which has no data fields. I kept Property in sample only to show what I want to achieve and why I might need such an empty table.

When doing the insert for Product, with a reference to an existing PropertyGroup, I have this error:
`pq: syntax error at or near "WHERE"`

Generated sql is this:
`UPDATE "property_groups" SET WHERE "property_groups"."id"=$1; - pq: syntax error at or near "WHERE"`

Of course an workaround might be to remove the autosave:"true" between Product and PropertyGroup, but this would break the insert when the PropertyGroup doesn't exist.

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.