Comments (8)
thank you soo much you are great!!!!!
from ra-strapi-rest.
Do you have any suggestions on how to account for this type of situations without breaking other scenarios (i.e. image upload) ? A pull request will be appreciated. Thank you!
from ra-strapi-rest.
Actually no I don't, the only solution I could do is this if
condition; other solution might be adding a custom endpoint on strapi to get the component's document.
I wished you knew a better way than mine; nevertheless; not sure if you would consider the approach of receiving a list of "KEY_IN_DOCUMENT_REFERS_TO_AN_ARRAY_OF_COMPONENTS"
like the one I used when initialing the data provider alongside the API link; that I can do a pull request for.. feels like a silly way to go but that can only other way be handled this way; or by customizing strapi to not send id in the component's object or sending "isComponent" key with it to use it as a reference
from ra-strapi-rest.
where to add above code?
from ra-strapi-rest.
@ranaharoon3222
Fnd the function replaceRefObjectsWithIds
, this is the one responsible for replacing the json[key]
with either the object's ID or array of IDs if the value was an array of components; there you should add your condition to not replace the value in the document if it was a component.
for me my code looked like this:
// Replace reference objects with reference object IDs
const replaceRefObjectsWithIds = (json) => {
Object.keys(json).forEach((key) => {
const fd = json[key]; // field data
const referenceKeys = [];
if (fd && (fd.id || fd._id) && !fd.mime) {
if (!isComponentsKeys(key)) {
json[key] = fd.id || fd._id;
} else {
delete fd.id;
}
} else if (Array.isArray(fd) && fd.length > 0 && !fd[0].mime) {
fd.map((item) => referenceKeys.push(item.id || item._id));
if (!isComponentsKeys(key)) {
json[key] = referenceKeys;
}
}
});
return json;
};
isComponentsKeys
is a function I defined to decide whether this is a component object or a populated object id for a document, you can add your logic there.
from ra-strapi-rest.
can you please share isComponentsKeys
function please
from ra-strapi-rest.
mine is as simple as:
const componentsKeys = [
"key1",
"key2"
];
function isComponentsKeys(k) {
return componentsKeys.indexOf(k) !== -1;
}
where I have documents like:
[
{
"id": "---",
"name:": "something",
"key1": {
"id": "component id",
"option": "some value"
},
"key2": [
{
"id": "component 2 id",
"option": "some value"
},
{
"id": "component 3 id",
"option": "some other value"
},
]
}
]
it's stupidly hard coded so you might have a better way.
from ra-strapi-rest.
Hi!
Please see the readme file. I have updated the package to make it work with Strapi V4. Please open a new issue if the problem persists.
Thanks!
from ra-strapi-rest.
Related Issues (20)
- updated/alt auth example HOT 2
- Get Entire File Url HOT 6
- User model CORS error HOT 2
- TypeError: _dataProvider_server_rest__WEBPACK_IMPORTED_MODULE_3__.strapiDataProvider.getOne is not a function HOT 5
- Suggestion: Replace Content-Range HOT 1
- ImageInput causes CastError: Cast to ObjectId failed for value "[]" at path "avatar" HOT 3
- Unable to show data in ArrayField HOT 2
- ReferenceField not displaying data in List view HOT 1
- Has and belongs to many relation HOT 1
- Handle Strapi validation errors HOT 4
- The dataProvider threw an error. It should return a rejected Promise instead.
- Add example for Relations to the Readme HOT 4
- N/A
- ImageInput causes CastError: Cast to ObjectId failed for value "[]" at path "avatar" HOT 1
- Strapi v4 is released HOT 4
- Single-Type Support HOT 1
- Fails with current version of strapi and react admin HOT 5
- No edit / or show buttons?
- Error for creating ressource HOT 1
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 ra-strapi-rest.