I have Events, which have multiple Deals, and each Deal has multiple Shotguns (tickets).
How can I list all the Shotguns of an Event, without having to go through each Deal?
Feature(s) impacted
Smart fields / smart relationships
Observed behavior
I was able to implement an Event
smart field on the Shotgun entity:
{
field: "Event",
type: "Number",
// isFilterable: true, // TODO
description: "The shotgun's deal's event",
reference: "events.id",
get: async (shotgun) => {
const [event] = await events.findAll({
include: [
{
model: deals,
as: "deals",
where: {
id: shotgun.dealId,
},
include: [
{
model: shotguns,
as: "shotguns",
where: {
id: shotgun.id,
},
},
],
},
],
});
// OR:
const deal = await DealDataloaders.byId.load(shotgun.dealId);
const event = await EventDataloaders.byId.load(deal.eventId);
return event;
},
},
Although Iâm not sure if itâs better to use include
or dataloaders (performance seems similar).
Expected behavior
Iâm failing to do the opposite listing: list an Eventâs Shotguns (without having to manually write a smart collection).
Context
- Project name: Shotgun admin
- Team name: Shotgun
- Environment name: Staging & production
- Agent (forest package) name & version:
forest-express-sequelize
9.2.8 - Database type: PG 14
- Recent changes made on your end if any: N/A