Why are all examples only arrays? #1584
-
As I was reading the documentation, I see examples of only arrays. Users, Posts, Comments etc. What if I have a It makes no sense to call a repository to get all records etc. How do I use Pinia ORM when I don't have an array? For example: import { defineStore } from 'pinia'
export const useAppStore = defineStore('app', () => {
const name = ref('My App')
const nameAndVersion = computed(() => `${name.value} v1.0.0`)
const changeName = (newName: string) => {
name.value = newName
}
return { name, nameAndVersion, changeName }
}, { persist: true }) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
If you use pinia-orm for a setting store then you can use it that way export interface SettingStore {
data: Setting,
nameAndVersion: string,
name: string
}
export default class Setting extends Model{
static entity = settings';
static piniaOptions = {
state: () => ({
data: {},
nameAndVersion : '1.0.0',
name : '',
}),
persist: true,
};
} and then you can access or update it through that way: const settings = useRepo(Setting).pinaStore<SettingStore>().$state
console.log(settings.name)
// Update
settings.name = 'Test' or for simple things if you use nuxt 3 just use |
Beta Was this translation helpful? Give feedback.
yes absolutly....pinia-orm isn't best for such case. And nothing speaks against using custom pina stores and pinia-orm models. It's totally normal to use both.