I'm in the process of developing a straightforward application that involves a one-to-many relationship between data entities. Specifically, I am working with feathers js and sequelize (utilizing sqlite) to create a system where each site can have multiple locations associated with it. While the standard GET
request in feathers allows for fetching sites or lists of sites effortlessly, retrieving child records poses a bit of a challenge.
If I were to tackle this directly using sequelize, my approach would look something like the following:
db.Site.findAll({
include: [db.Location]
}).then(function(sites) {
res.status(200).json({
data: sites
});
}).catch(err => res.status(500).send({ error: err }));
After consulting the feathers documentation, it appears that I could potentially address this issue by implementing a hook post the standard query procedure. This method would involve replacing the initially fetched data with the outcomes of an additional query, effectively doubling the number of database requests. Alternatively, I could execute separate queries solely for locations linked to the current siteId
, once again increasing the number of database calls.
Nevertheless, I find myself wondering if there exists a more elegant solution within feathers that could automatically include child elements every time a standard GET
call is made.