Comments (7)
I'm not sure what is causing this behaviour for you. The behaviour of the JSON spec is that it uses relationships if they are in the object, but if there is no relationship section at all then it won't remove them on the server.
In your above example, there is no _jv: { relationships: { ...}}
key so this patch should have no effect on the server.
Equally if the object you are using in the patch is one from the store, then it should include the relationship section it had when it was fetched, so there should be no change.
It might help to set the cleanPatch: true
config option when setting up the module - this will drop any keys in the patch that are also in the store. It is designed to stop out-of-date records in the store accidentally being 'added back' when a patch happens - but should also guarantee to remove all references to relationships etc.
Let us know if that helps?
from jsonapi-vuex.
Hi @mrichar1 !
Thanks for your quick reply.
I think my question was wrong.
When I send my PATCH request, I do not use the object (record) in the state, but only a raw JSON object: {_jv: {type: 'blogs', id: '1'}}
.
I think this is my issue.
But it might be a great option (or not) to add !? Something that could find an existing record before sending the PATCH request to make sure relationships are kept !
Example: mergeExistingOnPatch: true
.
The cleanPatch will help me because I only want to send what have been changed.
Francis.
from jsonapi-vuex.
Hi,
Creating a new object 'from scratch' shouldn't matter. If the object doesn't contain a relationships
section (in _jv
) then the patch won't modify any relationships. I've just tested this using the testapp provided with the library and it behaves as expected.
The store is empty, and the object I'm passing to the patch
action is:
{
_jv: {
type: 'widget',
id: '1',
},
color: 'red',
}
(Different type/attribute, but the same effect).
Can you let me know what JSONAPI server you are running/connecting to? There is a possibility that the implementation doesn't follow the JSONAPI spec correctly.
from jsonapi-vuex.
Hi,
I am using the Laravel JSON API package: https://laravel-json-api.readthedocs.io/en/latest/
I will make more tests and see what response I get and if the relationships section is in _jv
.
However, I do not say that the relationships are modified or removed from the server (database), I said that the relationships are removed from the Vuex store when the response of the PATCH request is parsed from your package.
All comments and tags are removed from the Vuex store.
from jsonapi-vuex.
Ahh - apologies - I thought you meant that the patch was removing relationships on the server-side. I now see what you mean!
With patch
the server can return no data (204) or a representation of the resulting patched object (200).https://jsonapi.org/format/#crud-updating-responses-200
If it returns 204, then the code already does a 'merge' of the patch object onto the store, so relationships should be unaffected.
If it returns 200, then the data should contain the relationships
section with the appropriate relationship identifier objects. Something like:
data: {
type: 'blogs',
id: '1'
attributes: {
published: false
},
relationships: {
tags: {
data; { type: 'tags', id: '10' }
},
comments: {
data: { type: 'comments', id: '20' }
}
}
Since the related items are already in the store (from the original get with include
) these will just create a reference 'pointing' to these objects.
Can you set the config option preserveJson: true
and then paste the contents of _jv/json
for the get
and patch
operations?
from jsonapi-vuex.
Hello, @mrichar1
I am new guy for this package and I'd like to use this one for my project.
So I have one issue and want your help.
I've got the json api like this.
baseUrl : https://dev-54ta5gq-2mtjdsd3z4gog.de-2.platformsh.site/jsonapi
method: Get,
its response looks like following
`
{
"jsonapi": {
"version": "1.0",
"meta": {
"links": {
"self": {
"href": "http://jsonapi.org/format/1.0/"
}
}
}
},
"data": [],
"links": {
"action--action": {
"href": "https://dev-54ta5gq-2mtjdsd3z4gog.de-2.platformsh.site/jsonapi/action/action"
},
"api_key--api_key": {
"href": "https://dev-54ta5gq-2mtjdsd3z4gog.de-2.platformsh.site/jsonapi/api_key/api_key"
},
"base_field_override--base_field_override": {
"href": "https://dev-54ta5gq-2mtjdsd3z4gog.de-2.platformsh.site/jsonapi/base_field_override/base_field_override"
}
}
}
`
I want to get the data from the href url related to the specific links key.
But I don't know how to do this.
Can you give me advice?
Thanks.
from jsonapi-vuex.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from jsonapi-vuex.
Related Issues (20)
- state should return function HOT 9
- Struggle to access some related / included data HOT 5
- Using href url HOT 4
- Problem when sorting with numbers HOT 1
- Option preserveJson ignored HOT 2
- Encoded type and id might cause to return undefined instead of stored object HOT 2
- Webpack - Failed to compile Error HOT 2
- Implement an http response in store is an anti-pattern HOT 4
- How to normalize keys from server HOT 2
- TypeError: property "system" is non-configurable and can't be deleted HOT 3
- HasMany relationships HOT 8
- How do I clear all records of a specific type?
- highlight highlight-source-js
- GetRelated constructs incorrect URLs instead of following relationship links HOT 5
- Pinia support HOT 3
- Missing option to deactivate url encoding in deleteRecord HOT 2
- CWE-1321 Vulnerability in lodash.set in version 4.5.3 HOT 1
- Meta object is missing when sending a PATCH request HOT 3
- Cannot access included records when using api/search HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonapi-vuex.