Refresh parent summary view on add in related data

I’m in a collection, let’s call it Houses. This house has rooms.
Houses.hasMany(Rooms)

In the house summary view, I display the largest room. When no rooms has been added to my house, this section is empty.

From the rooms related data, I click + and add a room. The newly added room is displayed on the related data table view.

But if I click on the summary tab, the “Largest room section” is still empty. I need to refresh the page in order to have it displayed.

I have been wondering how I can customize the response.send(...); so I can have my
await recordCreator.serialize(new created room)
and
{ refresh: { relationships: ['houseRooms'] } }

Here are POST route examples :

router.post('/managementMandates', permissionMiddlewareCreator.create(), (request, response) => {
  // Learn what this route does here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/routes/default-routes#create-a-record
  const recordCreator = new RecordCreator(models.managementMandates);
  const data = request.body.data.attributes;

  let place_id;
  if (request.body.data.relationships.integration) {
    place_id = request.body.data.relationships.integration.data.id;
  } else {
    place_id = request.body.data.relationships.place.data.id;
  }

  const body = {
    management_mandate: {
      place_id,
      start_date: new Date(data.startDate).toISOString(),
      end_date: new Date(data.endDate).toISOString(),
      annual_fees: data.annualFees * 100,
      comment: data.comment
    }
  };

  axios.post(`${API_URL}/forest_admin/management_mandates`, body, {
    headers: {
      'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`,
      'X-CURRENT-USER-EMAIL': request.user.email
    },
  }).then(async res => {
    response.send(await recordCreator.serialize(res.data));
  }).catch(err => {
    response.status(400).send({ error: err.response.data.error.message });
  });
});
router.post('/previousManagementAgents', permissionMiddlewareCreator.create(), (request, response, next) => {
  // Learn what this route does here: https://docs.forestadmin.com/documentation/v/v6/reference-guide/routes/default-routes#create-a-record
  const recordCreator = new RecordCreator(models.previousManagementAgents);
  const data = request.body.data.attributes;

  let place_id;
  if (request.body.data.relationships.integration) {
    place_id = request.body.data.relationships.integration.data.id;
  } else {
    place_id = request.body.data.relationships.place.data.id;
  }

  const body = {
    previous_management_agent: {
      place_id,
      kind: data.kind,
      archive_reception: data.archiveReception,
      identity_attributes: {
        last_name: data.nom,
        first_name: data.prenom,
        email: data.email,
        phone_number: data.telephone,
        address_attributes: {
          street_number: data.street_number,
          street: data.street,
          zip_code: data.zip_code,
          city: data.city,
          country: data.country,
          display_name: 'Coordonnées ancien syndic'
        }
      }
    }
  };

  axios.post(`${API_URL}/forest_admin/previous_management_agents`, body, {
    headers: {
      'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`,
      'X-CURRENT-USER-EMAIL': request.user.email
    },
  }).then(async res => {
    response.send(await recordCreator.serialize(res.data));
  }).catch(err => {
    response.status(400).send({ error: err.response.data.error.message });
  });
});

Hello @JeremyV,

Thanks for your message, that’s an interesting use case! :raised_hands:

I am trying to reproduce it, just to be sure, how do you “display the largest room” in your summary view? Is it a related data embedded into it?

Thanks.

Hello @anon34731316

In my case, the “largest room” is the “ongoing management mandate” or “previous management agent”. It’s just a bunch of smart fields grouped into a section of the parent summary view.

image
image

@JeremyV thanks for your answer!

Indeed, I’m able to reproduce the issue.
It seems to be a bug as in the create record API response, the smart field “largest room” seems to be well updated, but it has no effect on the summary view…
I’m opening a bug report so that we can tackle this later on.

Thanks for bringing that up!