Replies: 2 comments 7 replies
-
@jmikrut could you help out? In addition to what I wrote in my initial comment, I also want to add a |
Beta Was this translation helpful? Give feedback.
-
hey @hdodov, I found this discussion while looking for a way to show a readonly "field" of another collection that has a relationship field to the one I'm editing. your code seems to work for finding the entity, but I can't seem to figure out how to make the UI actually update with the value. basically I have an hooks: {
afterRead: [
async ({ doc }) => {
console.log({ doc });
const exam = doc.exam;
console.log({ exam });
if (!exam) {
console.log("no exam");
const relatedExam = await payload.find({
collection: "exams",
depth: 0,
where: {
questions: {
in: doc.id,
},
},
});
console.log({ relatedExam });
doc.exam = relatedExam.docs?.[0];
}
return doc;
},
], am I missing something to update the UI or should this be done in some other way? 🤔 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a posts collection and a categories collection. Posts have categories, but categories can have subcategories (which are other categories). Something like this:
Whenever a blog post is read, I want to also add the parent category of the post's selected category (if such exists). What would be the proper way to do that?
It seems to work with an after-read hook:
However, this results in two queries - one for the post and then one specifically for the parent category.
Is it possible to have Payload send a single query? I know that's possible in MongoDB with aggregation operations.
Beta Was this translation helpful? Give feedback.
All reactions