mirror of
https://github.com/pocketbase/pocketbase.git
synced 2026-10-27 07:20:26 +01:00
import scaffoldings
This commit is contained in:
1 parent
95f9d685dc
commit
f459dd8812
25 files changed
+1362
-261
No files matched your search
+11
-1
@@ -128,7 +128,7 @@ func (dao *Dao) Delete(m models.Model) error {
|
||||
|
||||
// Save upserts (update or create if primary key is not set) the provided model.
|
||||
func (dao *Dao) Save(m models.Model) error {
|
||||
if m.HasId() {
|
||||
if !m.IsNew() {
|
||||
return dao.update(m)
|
||||
}
|
||||
|
||||
@@ -140,6 +140,10 @@ func (dao *Dao) update(m models.Model) error {
|
||||
return errors.New("ID is not set")
|
||||
}
|
||||
|
||||
if m.GetCreated().IsZero() {
|
||||
m.RefreshCreated()
|
||||
}
|
||||
|
||||
m.RefreshUpdated()
|
||||
|
||||
if dao.BeforeUpdateFunc != nil {
|
||||
@@ -195,6 +199,9 @@ func (dao *Dao) create(m models.Model) error {
|
||||
|
||||
if v, ok := any(m).(models.ColumnValueMapper); ok {
|
||||
dataMap := v.ColumnValueMap()
|
||||
if _, ok := dataMap["id"]; !ok {
|
||||
dataMap["id"] = m.GetId()
|
||||
}
|
||||
|
||||
_, err := dao.db.Insert(m.TableName(), dataMap).Execute()
|
||||
if err != nil {
|
||||
@@ -206,6 +213,9 @@ func (dao *Dao) create(m models.Model) error {
|
||||
}
|
||||
}
|
||||
|
||||
// clears the internal isNewFlag
|
||||
m.UnmarkAsNew()
|
||||
|
||||
if dao.AfterCreateFunc != nil {
|
||||
dao.AfterCreateFunc(dao, m)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user