vuex-orm / vuex-orm

The Vuex plugin to enable Object-Relational Mapping access to the Vuex Store.

Home Page:https://vuex-orm.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Docs] entities defined in persistOptions should be singular

dschreij opened this issue · comments

Describe the bug

I had been breaking my head on why my persistOptions parameters were not working, because I thought I followed the docs, but I found there may be an error in the docs.
I have a model Shipment (shipment), which has as hasMany relation to two models CargoComponent (entity: cargo_component) and Container (entity: container). When shipment is updated, I want to refresh the data of the related entities. According to the docs at https://vuex-orm.github.io/plugin-axios/guide/usage.html#performing-requests, this can be done by passing a create entry in persistOptions for the entities you would like to refresh, and the example given there is:

User.api().get('/api/users', {
  persistOptions: {
    insert: ['posts']
  }
})

which shows the entity name posts in plural, so naturally I tried:

persistOptions: {
   create: ['cargo_components', 'containers']
},

but that didn't work! When I passed the entity names as singular, it did work:

persistOptions: {
   create: ['cargo_component', 'container']
}

Are the docs wrong here, or am I missing something else? How are the related entities supposed to be indicated in this function, in singular or plural?

Hmm I see that the error might be on my side after all. In the models themselves I had defined the entity names as singular, and the vuex-orm docs define them as plural. In that light, I think this issue can be closed.

commented

Not sure what the issue here actually is but I suspect the entities you're passing to persistOptions do not marry with what you've defined in your model schemas.

I think it matters not whether the entities are singular or plural (although plural seems to be the Laravel favourite), they just need to match what is defined in the schema registry.

I suspect the entities you're passing to persistOptions do not marry with what you've defined in your model schemas.

That was exactly the case. I used plural in persistOptions and singular forms as the entity names.