Reputation: 81
I have the following Media schema
module.exports = {
attributes: {
user: {
model: 'user',
required: true
},
jobs: {
collection: 'job',
via: 'media'
}
},
afterCreate: generateJob,
}
The method generateJob the media object is like that
{
user: '55dcd2db428f50ea1ecf670e'
}
But job field doesnt appear and I need it because I want to associate one job to media but media doesnt get the media.jobs.add() method.
Thanks
Upvotes: 1
Views: 25
Reputation:
In order to retrieve the data from an association, you must invoke the .populate()
method; waterline does not automatically populate this data (it it is too expensive and too rarely necessary to be a core feature, in my humble opinion).
Somewhere along the line (e.g. in generateJob
), you'll need to do something like this:
Media.find(...).populate('jobs')
, at which point you'll be able to invoke .add()
and .remove()
on the associated collection.
Upvotes: 1