-
-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to update 'hasManyBy'? #101
Comments
Oh OK, this is yes a problem. Sorry I haven't thought enough about updating Array... This issue must have some kind of solution, but for now as a workaround, please use This problem is not specific to I'm thinking 3 steps here for the update method improvement.
// State.
{
schemas: {
data: {
'1': {
id: 1,
name: 'Schema Name',
parameters: [1, 2]
}
}
}
}
// Update array.
store.dispatch('entities/schemas/update', {
where: 1,
data: { parameters: [3] }
})
// Then in the state.
{
schemas: {
data: {
'1': {
id: 1,
name: 'Schema Name',
parameters: [3] // <- Replaced!
}
}
}
}
// State.
{
schemas: {
data: {
'1': {
id: 1,
name: 'Schema Name',
parameters: [1, 2]
}
}
}
}
// Update array with closure.
store.dispatch('entities/schemas/update', {
where: 1,
data (record) {
record.parameters.push(3)
}
})
// Then in the state.
{
schemas: {
data: {
'1': {
id: 1,
name: 'Schema Name',
parameters: [1, 2, 3] // <- Updated!
}
}
}
}
// State.
{
schemas: {
data: {
'1': {
id: 1,
name: 'Schema Name',
parameters: [1, 2]
}
}
}
}
// Update array with special action.
store.dispatch('entities/schemas/push', {
where: 1,
field: 'parameters',
data: 3
})
// Then in the state.
{
schemas: {
data: {
'1': {
id: 1,
name: 'Schema Name',
parameters: [1, 2, 3] // <- Updated!
}
}
}
} Maybe 3 is too much. But I think 1 is a must. What do you think? /Cc @iNaD May I ask you for your idea on this topic (since it is about update 😃 )? |
thanks for your reply, i played vuex-orm a whole day, the first way is my hope, 😃 ,will make data structure simple |
Thanks for confirming! yea the 1st should is a must I think! We should work on to it. |
This issue has been fixed with Vuex ORM 0.22.0 🎉 Thank you for raising this issue! Hope this will will make your coding easier 👍 |
i have a very complex project, vuex-orm saved me. but how to update array?
demo
when update hasManyBy field, array be merged (in demo case, parameter cannot by delete);
i found the code:
how to solve the problem? thx!
The text was updated successfully, but these errors were encountered: