Ok so, I suggest you to have a look on this documentation related to smart relation ship feature
.
Adapted to your goal,
You need to create a smart collection who represent your log entries
.
Like this
const { collection } = require('forest-express-sequelize');
collection('log', {
actions: [],
fields: [{
field: 'content',
type: 'String',
}, {
field: 'log creation',
type: 'Date',
}, {
...
}],
segments: [],
});
Next You need to define a smart relationship between your user
model and your new log
model.
like this
const { collection } = require('forest-express-sequelize');
collection('user', {
actions: [],
fields: [{
field: 'logs',
type: ['Number'],
reference: 'log.id'
}],
segments: [],
});
After that you will be able to see, in the ui, the associated related data under user detail.
The last thing you need is to fill data now.
You mus create the new relationship route like this.
router.get('/user/:userId/relationships/logs', async (request, response, next) => {
const recordSerializer = new RecordSerializer({ name: 'log' });
const records = await yourApiCall();// call your api with request.params.userId
// WRNING! you need to have id inside your records.
// here we want to have plain object who represent the log collection you declared before
const serializedRecords = await recordSerializer.serialize(records, { count: records.length });
response.send(serializedRecords);
});
Now you should be able to see inside user related data your logs.
I let you play with our smart feature and the little exemple i provided.
Please don’t hesitate to come back if you have any question.