apostrophe-cms

apostrophe cms data retrieval of join of pieces with join of another piece


**The code given below are the schema fields of a piece called home and home has pieces joined with it such as _trip, _accomodation, _testimonial.These joined pieces are again joined with other pieces in their schema.so on retrieving the home piece using api/v1/home the the inner joins of joined pieces are displayed as id.

How do I get data of that id's???**

 {
      name: '_trip',
      label: 'Spotlight Trips',
      limit:4,
      type: 'joinByArray',
      withType: 'trip',
    },
    {
      name: '_accommodation',
      label: 'Spotlight Accommodations',
      type: 'joinByArray',
      withType: 'accommodation',
      limit:2,
    },
    {
      name: '_testimonial',
      label: 'Testimonials',
      type: 'joinByArray',
      withType: 'testimonial'
    },

The json given given below is a portion of the data retrived.I want to get the data of accommodation and trips which is another piece , But instead here its id's are shown.

"_home-spotlight": [
        {
          "_id": "cki5owqrv008obgundta0x6rp",
          "published": true,
          "trash": false,
          "type": "home-spotlight",
          "title": "spotlightAbove",
          "tripIds": [
            "cki5oqi7r0063bgun81o6umqd"
          ],
          "accommodationIds": [
            "cki5owga1008mbgunlxweuera"
          ],

Solution

  • Currently, ApostropheCMS has no way to fetch contents from inner joins (that is, the collection joins has another collection joined) through Rest API. For now, we will get only the IDs of that collection. So as, alexbea said, we have to do an another additional API call to fetch that collection using the IDs.

    Those who are not using Rest API can fetch these collections using withJoins [https://docs.apostrophecms.org/reference/field-types/joinbyarray.html#settings].