fix: assciasions update
This commit is contained in:
@@ -20,7 +20,7 @@ export function Count(): Promise<number> & { cancel(): void } {
|
|||||||
|
|
||||||
export function Create(item: $models.Author): Promise<$models.Author> & { cancel(): void } {
|
export function Create(item: $models.Author): Promise<$models.Author> & { cancel(): void } {
|
||||||
let $resultPromise = $Call.ByID(3684602449, item) as any;
|
let $resultPromise = $Call.ByID(3684602449, item) as any;
|
||||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
let $typingPromise = $resultPromise.then(($result) => {
|
||||||
return $$createType0($result);
|
return $$createType0($result);
|
||||||
}) as any;
|
}) as any;
|
||||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
$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 } {
|
export function GetAll(): Promise<($models.Author | null)[]> & { cancel(): void } {
|
||||||
let $resultPromise = $Call.ByID(3248293926) as any;
|
let $resultPromise = $Call.ByID(3248293926) as any;
|
||||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
let $typingPromise = $resultPromise.then(($result) => {
|
||||||
return $$createType2($result);
|
return $$createType2($result);
|
||||||
}) as any;
|
}) as any;
|
||||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
$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 } {
|
export function GetById(id: number): Promise<$models.Author | null> & { cancel(): void } {
|
||||||
let $resultPromise = $Call.ByID(1703016211, id) as any;
|
let $resultPromise = $Call.ByID(1703016211, id) as any;
|
||||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
let $typingPromise = $resultPromise.then(($result) => {
|
||||||
return $$createType1($result);
|
return $$createType1($result);
|
||||||
}) as any;
|
}) as any;
|
||||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
$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 } {
|
export function Update(item: $models.Author): Promise<$models.Author> & { cancel(): void } {
|
||||||
let $resultPromise = $Call.ByID(2240704960, item) as any;
|
let $resultPromise = $Call.ByID(2240704960, item) as any;
|
||||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
let $typingPromise = $resultPromise.then(($result) => {
|
||||||
return $$createType0($result);
|
return $$createType0($result);
|
||||||
}) as any;
|
}) as any;
|
||||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export function Count(): Promise<number> & { cancel(): void } {
|
|||||||
|
|
||||||
export function Create(item: $models.Post): Promise<$models.Post> & { cancel(): void } {
|
export function Create(item: $models.Post): Promise<$models.Post> & { cancel(): void } {
|
||||||
let $resultPromise = $Call.ByID(1443399856, item) as any;
|
let $resultPromise = $Call.ByID(1443399856, item) as any;
|
||||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
let $typingPromise = $resultPromise.then(($result) => {
|
||||||
return $$createType0($result);
|
return $$createType0($result);
|
||||||
}) as any;
|
}) as any;
|
||||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
$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 } {
|
export function GetAll(): Promise<($models.Post | null)[]> & { cancel(): void } {
|
||||||
let $resultPromise = $Call.ByID(65691059) as any;
|
let $resultPromise = $Call.ByID(65691059) as any;
|
||||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
let $typingPromise = $resultPromise.then(($result) => {
|
||||||
return $$createType2($result);
|
return $$createType2($result);
|
||||||
}) as any;
|
}) as any;
|
||||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
$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 } {
|
export function GetById(id: number): Promise<$models.Post | null> & { cancel(): void } {
|
||||||
let $resultPromise = $Call.ByID(4074736792, id) as any;
|
let $resultPromise = $Call.ByID(4074736792, id) as any;
|
||||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
let $typingPromise = $resultPromise.then(($result) => {
|
||||||
return $$createType1($result);
|
return $$createType1($result);
|
||||||
}) as any;
|
}) as any;
|
||||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
$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 } {
|
export function Update(item: $models.Post): Promise<$models.Post> & { cancel(): void } {
|
||||||
let $resultPromise = $Call.ByID(137798821, item) as any;
|
let $resultPromise = $Call.ByID(137798821, item) as any;
|
||||||
let $typingPromise = $resultPromise.then(($result: any) => {
|
let $typingPromise = $resultPromise.then(($result) => {
|
||||||
return $$createType0($result);
|
return $$createType0($result);
|
||||||
}) as any;
|
}) as any;
|
||||||
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
$typingPromise.cancel = $resultPromise.cancel.bind($resultPromise);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ onMounted(async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const scheme: Scheme<Author> = reactive({
|
const scheme: Scheme<Author> = reactive({
|
||||||
|
entityId: "AuthorId",
|
||||||
Id: {
|
Id: {
|
||||||
hidden: true,
|
hidden: true,
|
||||||
type: {
|
type: {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const pushOrRemove = (option: T) => {
|
|||||||
} else {
|
} else {
|
||||||
selected.value.push(option)
|
selected.value.push(option)
|
||||||
}
|
}
|
||||||
setNullIds()
|
//setNullIds()
|
||||||
}
|
}
|
||||||
|
|
||||||
const setNullIds = () => {
|
const setNullIds = () => {
|
||||||
@@ -28,7 +28,7 @@ const setNullIds = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(setNullIds)
|
//onMounted(setNullIds)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ onMounted(async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const scheme: Scheme<Post> = reactive({
|
const scheme: Scheme<Post> = reactive({
|
||||||
|
entityId: "PostId",
|
||||||
Id: {
|
Id: {
|
||||||
hidden: true,
|
hidden: true,
|
||||||
type: {
|
type: {
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ const emits = defineEmits<{
|
|||||||
</div>
|
</div>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<Button severity="success" @click="async () => {
|
<Button severity="success" @click="async () => {
|
||||||
console.log(createItem)
|
|
||||||
if (props.updateMode) {
|
if (props.updateMode) {
|
||||||
await props.service.update(createItem as T)
|
await props.service.update(createItem as T)
|
||||||
await emits('onSaveUpdate', createItem as T)
|
await emits('onSaveUpdate', createItem as T)
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import (
|
|||||||
"app/internal/dal"
|
"app/internal/dal"
|
||||||
"gorm.io/driver/sqlite"
|
"gorm.io/driver/sqlite"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"gorm.io/gorm/logger"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -18,7 +20,19 @@ const Path = "database.db"
|
|||||||
|
|
||||||
func initialize() error {
|
func initialize() error {
|
||||||
var err 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ type Post struct {
|
|||||||
Text string `displayName:"Текст" ui:"label:Текст"`
|
Text string `displayName:"Текст" ui:"label:Текст"`
|
||||||
Deadline int64 `ui:"label:Дедлайн;datatype:datetime;"`
|
Deadline int64 `ui:"label:Дедлайн;datatype:datetime;"`
|
||||||
CreatedAt int64 `gorm:"autoCreateTime" ui:"readonly;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;"`
|
Author Author `ui:"label:Автор; field:Name;"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Author struct {
|
type Author struct {
|
||||||
Id uint `gorm:"primaryKey" ui:"hidden"`
|
Id uint `gorm:"primaryKey" ui:"hidden"`
|
||||||
Name string `ui:"label:Имя;"`
|
Name string `ui:"label:Имя;"`
|
||||||
Posts []Post `ui:"label:Посты; field:Text;"`
|
Posts []Post `ui:"label:Посты; field:Text;" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;"`
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,12 @@ func (service *AuthorService) GetById(id uint) (*Author, error) {
|
|||||||
return item, nil
|
return item, nil
|
||||||
}
|
}
|
||||||
func (service *AuthorService) Update(item Author) (Author, error) {
|
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
|
return item, err
|
||||||
}
|
}
|
||||||
func (service *AuthorService) Delete(id uint) error {
|
func (service *AuthorService) Delete(id uint) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user