I am learning the ropes of Meteor and kind of lost here. I am using collections2, autoform for building my application. I want to store the collection along with user id information. So that when we retrieve the collection from the server, I want to show only the ones the user created not everything else. here is the schema.
ExercisesSchema = new SimpleSchema({
"name": {
type: String,
label: 'Name'
},
"workout.$.weight": {
type: String,
label: 'Weight'
},
"workout.$.reps": {
type: String,
label: 'Reps'
},
"notes": {
type: String,
label: 'Notes',
optional: true
}
});
on the server side I want to show only the workouts created by the user
Meteor.publish('exercises', function () {
return Exercises.find({owner: this.userId});
});
When I added the user id to the schema, it shows up in the autoform, I am not sure how to hide it, if I hide it, then possibly I can use hooks in the autoform to add the values?
You could try the
before
hook approach:In your template:
Then your
autoform.js
The above adds the ownerId on the fly just when about to save to collection.
As stated in the docs on atmospherejs.com/aldeed/autoform:
In the schema you can define the ownerId as type: "hidden"
schema.js
And populate it with the hooks as you said.
autoFormHooks.js
An alternative to using hooks would be to use a quickFields inside of your autoForm for each field that you want to set in the doc, including ownerId. With this solution you would set the
value
of ownerId tocurrentUser
.template.js