Update address foreign key when updating the address
This commit is contained in:
parent
dcab2e1f8f
commit
ffedae0373
1 changed files with 16 additions and 0 deletions
|
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/Gleipnir-Technology/bob"
|
"github.com/Gleipnir-Technology/bob"
|
||||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||||
|
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||||
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
||||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||||
"github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
"github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
||||||
|
|
@ -311,6 +312,21 @@ func publicReportUpdateAddress(ctx context.Context, txn bob.Executor, report *mo
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("update report: %w", err)
|
return fmt.Errorf("update report: %w", err)
|
||||||
}
|
}
|
||||||
|
_, err = psql.Update(
|
||||||
|
um.Table("publicreport.report"),
|
||||||
|
um.SetCol("address_id").To(
|
||||||
|
psql.Select(
|
||||||
|
sm.Columns("id"),
|
||||||
|
sm.From("address"),
|
||||||
|
sm.Where(psql.Quote("gid").EQ(psql.Arg(address.GID))),
|
||||||
|
sm.Limit(1),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
um.Where(psql.Quote("publicreport", "report", "id").EQ(psql.Arg(report.ID))),
|
||||||
|
).Exec(ctx, txn)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("update report address_id: %w", err)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func publicReportUpdateLocation(ctx context.Context, txn bob.Executor, id int32, location types.Location) error {
|
func publicReportUpdateLocation(ctx context.Context, txn bob.Executor, id int32, location types.Location) error {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue