sails.js - how can I acess session data in Model hook beforeCreate
I want to update a field 'owner' of a Model. The owner needs to be fetched from the session which contains the user who is currently logged in and is creating the Model. I want something like this: Model = { attributes: { }, beforeCreate(values,next) { var owner_user_id = req.session.user_id; values.owner = owner_user_id; next(); } } Are you sure a lifecycle callback is the right place to do it? Because it's really not. What if tomorrow you'll need to use your model in a CLI task or something else sessionless? Besides, with the associations API coming, there will be, probably, a more elegant