-1

how to put the full object workstation in another object userWorkstationSchedule?

code:

Workstation.js

module.exports = {
    tableName: 'workstation',
    attributes: {
        name: { type: 'string', required: true, maxLength: 100, columnType: 'VARCHAR(100)' },

        company: { model: 'company', required: true },

        workDates: { collection: 'workstationSchedule', via: 'workstation'},
        reservedDates: {collection: 'userWorkstationSchedule', via: 'workstation'},

      }
}

reservedDates attribute receives data from the userWorkstationSchedule object UserWorkstationSchedule.js

module.exports = {
    tableName: 'user_workstation_schedule',
    attributes: {
          presenceSchedules: { collection: 'presenceschedule', via: 'userWorkstationSchedule' },
          workstation: {collection: 'workstation', via: 'reservedDates'},
  }
}
comodo
  • 1

1 Answers1

0

You don't need to put "the full object", he is already in, and that's the power of Sails.js and of any ORM.

Data fecthing is made asynchronously and "lazy". (More info about LazyLoading)

The ORM load only what is absolutely necessary and not all the linked associations.

In Sails.js, when you need a particular data, you need to populate it via the .populate() method.

var userWorkstationSchedule = await UserWorkstationSchedule.find().populate('workstation');

You can find more about populate in Sails.JS Documentation

Lucas Duval
  • 188
  • 1
  • 7