Comments (2)
While this isn't an issue with the axios plugin per-se, it seems to point to either Vuex ORM or json-api-response-converter.
Currently a morphTo
relation expects the id
and type
to exist in the given record since it doesn't need to attach foreign keys to the related model. Given your transformed data doesn't provide that, the necessary relations are not generated. For example, the following payload will generate the relations for a morphTo
:
Activity.insert({
data: {
id: 'a1',
causer_id: 'u1',
causer_type: 'users',
causer: { id: 'u1', name: 'Admin' }
}
})
I'm not sure if this is Vuex ORM just not generating the missing foreign keys (something @kiaking could shed light on perhaps?)... But As a workaround, you could attach the would-be foreign keys to the Activity model in the transformer:
static apiConfig = {
dataTransformer: (response) => {
const data = new JsonApiResponseConverter(response.data).formattedResponse
data.forEach((item, index) => {
if (item.causer) {
data[index].causer_id = item.causer.id
data[index].causer_type = 'users'
}
if (item.subject) {
data[index].subject_id = item.subject.id
data[index].subject_type = 'institutes'
}
})
return data
}
}
Here's a workable fork.
from plugin-axios.
Thanks for responding my issue @cuebit, the reason why I'm asked here instead of on vuex-orm package, is because of the dataTransformer timing so that I can provides data with expected morph to format.
This case is using User as causer and Institute as subject, anyway how can I guess the type of related data if I have registered 44 models on vuex-orm database?
Another point to mention is JSON:API prefers kebab-case on resource's type, but vuex-orm prefers snake-case on model's entity. Should I make a morph map to solve this case?
from plugin-axios.
Related Issues (20)
- API Response then(response) not equal catch(response) HOT 1
- API request result.entities contains records in a different order than they were returned from the server. HOT 1
- issue with using with nuxt-i18n, language is appended to all api calls HOT 2
- persistBy: "create" not deleteAll data on relation HOT 5
- Handling of response errors HOT 1
- Update relationships on fetch HOT 1
- Inserting multiple records at once. HOT 2
- Retrieving Users with M:M relationship is causing infinite loop in mounted() HOT 3
- Outdated axios dependency HOT 1
- Setup issues with vue3 - Item.api is not a function HOT 10
- axios config URL HOT 1
- Relationships dataKey HOT 1
- retrieve store from single get HOT 2
- Ability to extend the Request class (global custom actions?) HOT 1
- Request: please pass the model class to dataTransformer HOT 2
- InsertIgnore HOT 1
- Documentation for persistyBy option: Add link to explanation of insert vs. create
- Mapping multiple entities from one response HOT 1
- Entity Briefly Enters a Truncated State Before Deletion When Using Vuex-ORM Axios Plugin when i dont add delete option
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 plugin-axios.