is there a problem with update model in 1.5.1? #940
Answered
by
rbartholomay
rbartholomay
asked this question in
Q&A
-
In my application i use multiple useRepo(MyModel). I have own methods for useUpdater, useRemover, useFetcher etc. export default function useNzfEventsUpdater() {
const repo = useRepo(NzfEvent);
function update(id: number | string, data: Partial<NzfEvent>) {
if (id) {
const payLoad = Object.assign(
{
id: id,
},
data
);
repo.save(payLoad);
}
}
return {
update,
repo,
};
}
export { useNzfEventsUpdater }; import { useRepo } from 'pinia-orm';
import NzfEvent from '../NzfEvent';
export default function useNzfEventsRemover() {
const repo = useRepo(NzfEvent);
function remove(id: number | string) {
if (id) {
repo.destroy(id);
}
}
return {
remove,
repo,
};
}
export { useNzfEventsRemover }; When i include this in a page like this it fails in 1.5.1 (only the repo data of nzfEventsUpdater.repo will show the new data) In 1.4.0 all runs fine - both repos data will shown the new data. Any idea? import useNzfEventsRemover from './useNzfEventsRemover';
import useNzfEventsUpdater from './useNzfEventsUpdater';
const nzfEventsRemover = useNzfEventsRemover();
const nzfEventsUpdater = useNzfEventsUpdater();
onMounted(() => {
const repo = nzfEventsRemover.repo;
repo.save([
{
id: 5,
title: 'Heiligabend',
details: 'Heiligabend',
date: '2022-12-24',
bgcolor: 'orange',
icon: 'autorenew',
periodic: true,
},
{
id: 6,
title: '1. Weihnachtstag',
details: '1. Weihnachtstag',
date: '2022-12-25',
bgcolor: 'red',
icon: 'autorenew',
periodic: true,
},
]);
});
function onBntClick() {
const repo = nzfEventsUpdater.repo;
repo.save({
id: 5,
title: 'Test1234',
details: 'Test1234',
date: '2022-12-24',
bgcolor: 'orange',
icon: 'autorenew',
periodic: true,
});
}
</script>
<template>
<div>
<pre>{{ nzfEventsRemover.repo.all() }}</pre>
</div>
<div>
<pre>{{ nzfEventsUpdater.repo.all() }}</pre>
</div>
<q-btn label="update" @click="onBntClick"></q-btn>
</template> |
Beta Was this translation helpful? Give feedback.
Answered by
rbartholomay
Feb 8, 2023
Replies: 1 comment
-
I refactor my code to have all crud operations in one file and solve the problem.. 😊 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
rbartholomay
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I refactor my code to have all crud operations in one file and solve the problem..
😊