fix: assciasions update

This commit is contained in:
2025-03-09 15:10:43 +07:00
parent df7c061d3a
commit 9e49d16a43
9 changed files with 36 additions and 16 deletions

View File

@@ -20,7 +20,7 @@ export function Count(): Promise<number> & { cancel(): void } {
export function Create(item: $models.Author): Promise<$models.Author> & { cancel(): void } {
let $resultPromise = $Call.ByID(3684602449, item) as any;
let $typingPromise = $resultPromise.then(($result: any) => {
let $typingPromise = $resultPromise.then(($result) => {
return $$createType0($result);
}) as any;
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
@@ -34,7 +34,7 @@ export function Delete(id: number): Promise<void> & { cancel(): void } {
export function GetAll(): Promise<($models.Author | null)[]> & { cancel(): void } {
let $resultPromise = $Call.ByID(3248293926) as any;
let $typingPromise = $resultPromise.then(($result: any) => {
let $typingPromise = $resultPromise.then(($result) => {
return $$createType2($result);
}) as any;
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
@@ -43,7 +43,7 @@ export function GetAll(): Promise<($models.Author | null)[]> & { cancel(): void
export function GetById(id: number): Promise<$models.Author | null> & { cancel(): void } {
let $resultPromise = $Call.ByID(1703016211, id) as any;
let $typingPromise = $resultPromise.then(($result: any) => {
let $typingPromise = $resultPromise.then(($result) => {
return $$createType1($result);
}) as any;
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
@@ -52,7 +52,7 @@ export function GetById(id: number): Promise<$models.Author | null> & { cancel()
export function Update(item: $models.Author): Promise<$models.Author> & { cancel(): void } {
let $resultPromise = $Call.ByID(2240704960, item) as any;
let $typingPromise = $resultPromise.then(($result: any) => {
let $typingPromise = $resultPromise.then(($result) => {
return $$createType0($result);
}) as any;
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);

View File

@@ -20,7 +20,7 @@ export function Count(): Promise<number> & { cancel(): void } {
export function Create(item: $models.Post): Promise<$models.Post> & { cancel(): void } {
let $resultPromise = $Call.ByID(1443399856, item) as any;
let $typingPromise = $resultPromise.then(($result: any) => {
let $typingPromise = $resultPromise.then(($result) => {
return $$createType0($result);
}) as any;
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
@@ -39,7 +39,7 @@ export function ExportToExcel(): Promise<void> & { cancel(): void } {
export function GetAll(): Promise<($models.Post | null)[]> & { cancel(): void } {
let $resultPromise = $Call.ByID(65691059) as any;
let $typingPromise = $resultPromise.then(($result: any) => {
let $typingPromise = $resultPromise.then(($result) => {
return $$createType2($result);
}) as any;
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
@@ -48,7 +48,7 @@ export function GetAll(): Promise<($models.Post | null)[]> & { cancel(): void }
export function GetById(id: number): Promise<$models.Post | null> & { cancel(): void } {
let $resultPromise = $Call.ByID(4074736792, id) as any;
let $typingPromise = $resultPromise.then(($result: any) => {
let $typingPromise = $resultPromise.then(($result) => {
return $$createType1($result);
}) as any;
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
@@ -57,7 +57,7 @@ export function GetById(id: number): Promise<$models.Post | null> & { cancel():
export function Update(item: $models.Post): Promise<$models.Post> & { cancel(): void } {
let $resultPromise = $Call.ByID(137798821, item) as any;
let $typingPromise = $resultPromise.then(($result: any) => {
let $typingPromise = $resultPromise.then(($result) => {
return $$createType0($result);
}) as any;
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);

View File

@@ -16,6 +16,7 @@ onMounted(async () => {
});
const scheme: Scheme<Author> = reactive({
entityId: "AuthorId",
Id: {
hidden: true,
type: {

View File

@@ -18,7 +18,7 @@ const pushOrRemove = (option: T) => {
} else {
selected.value.push(option)
}
setNullIds()
//setNullIds()
}
const setNullIds = () => {
@@ -28,7 +28,7 @@ const setNullIds = () => {
})
}
onMounted(setNullIds)
//onMounted(setNullIds)
</script>
<template>

View File

@@ -16,6 +16,7 @@ onMounted(async () => {
});
const scheme: Scheme<Post> = reactive({
entityId: "PostId",
Id: {
hidden: true,
type: {

View File

@@ -72,7 +72,6 @@ const emits = defineEmits<{
</div>
<template #footer>
<Button severity="success" @click="async () => {
console.log(createItem)
if (props.updateMode) {
await props.service.update(createItem as T)
await emits('onSaveUpdate', createItem as T)

View File

@@ -4,7 +4,9 @@ import (
"app/internal/dal"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"log"
"os"
"sync"
"time"
)
@@ -18,7 +20,19 @@ const Path = "database.db"
func initialize() error {
var err error
db, err = gorm.Open(sqlite.Open("file:"+Path+"?_fk=1"), &gorm.Config{})
newLogger := logger.New(
log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer
logger.Config{
SlowThreshold: time.Second, // Slow SQL threshold
LogLevel: logger.Info, // Log level
IgnoreRecordNotFoundError: false, // Ignore ErrRecordNotFound error for logger
ParameterizedQueries: false, // Don't include params in the SQL log
Colorful: true, // Disable color
},
)
db, err = gorm.Open(sqlite.Open("file:"+Path+"?_fk=1"), &gorm.Config{
Logger: newLogger,
})
if err != nil {
return err
}

View File

@@ -9,12 +9,12 @@ type Post struct {
Text string `displayName:"Текст" ui:"label:Текст"`
Deadline int64 `ui:"label:Дедлайн;datatype:datetime;"`
CreatedAt int64 `gorm:"autoCreateTime" ui:"readonly;datatype:datetime;"`
AuthorId uint `ui:"hidden"`
AuthorId uint `ui:"hidden" gorm:"foreignKey:Id;references:AuthorId;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
Author Author `ui:"label:Автор; field:Name;"`
}
type Author struct {
Id uint `gorm:"primaryKey" ui:"hidden"`
Name string `ui:"label:Имя;"`
Posts []Post `ui:"label:Посты; field:Text;"`
Posts []Post `ui:"label:Посты; field:Text;" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
}

View File

@@ -33,7 +33,12 @@ func (service *AuthorService) GetById(id uint) (*Author, error) {
return item, nil
}
func (service *AuthorService) Update(item Author) (Author, error) {
err := dal.Author.Preload(field.Associations).Save(&item)
var posts []*models.Post
for _, post := range item.Posts {
posts = append(posts, &post)
}
err := dal.Author.Posts.Model(&item).Replace(posts...)
_ = dal.Author.Save(&item)
return item, err
}
func (service *AuthorService) Delete(id uint) error {