Pinia Options


Under the hood Pinia ORM uses the defineStore method to create the pinia store for each model. You still have of course the option to pass pinia options through a configuration in the model

Extending the store options (e.g. for plugins)

Maybe you want to use some other pinia plugins like Pinia Plugin Persistedstate. And therefor you need to be able to pass otpions to your store definition.

user.ts
import { Model, Attr, Str } from 'pinia-orm'import Post from '@/models/Post'class User extends Model {  static entity = 'users'  @Attr(null)  id!: number | null  @Str('')  name!: string    static piniaOptions = {      persist: true  }}

Overwriting (e.g. actions)

Through this options you can also overwrite the default pinia actions and add even properties to the state.

user.ts
import { Model, Attr, Str, useStoreActions, Elements } from 'pinia-orm'import Post from '@/models/Post'class User extends Model {  static entity = 'users'  @Attr(null)  id!: number | null  @Str('')  name!: string    static piniaOptions = {      actions: {          ...useStoreActions(),          save(records: Elements) {            console.log('I am saving data!')            this.data = { ...this.data, ...records }          },      }  }}