Hello. I am trying to figure out why I cant get simple results from a nested class. Each is assigning random _ids to my data when they already have _ids assigned. Here is the spacebars documentation about it … How come it will correctly display the name and team but doesnt display the other information, something with how I am setting it?
I feel like I must be missing something simple here to get this working. I have tried so many different ways to set the _id, afterInit, beforeSet, etc, but those efforts have been unfruitful in solving this. What am I getting wrong here?
<template name="matchChannel">
{{#with aMatch}}
{{> matchTeamDisplay}}
{{/with}}
</template>
<template name="matchTeamDisplay">
<div class="ui middle aligned list" id="readyUpPlayers">
{{#each players}}
<div class="item">
{{name}} --- {{team}} --- {{_id}}----{{readyUp}}----
<input type="checkbox" {{b "check: {{readyUp}}"}}>
</div>
{{/each}}
</template>
&&& I am using Viewmodel and Astronomy, their code is below…
Template.matchChannel.viewmodel({
aMatch: function(){
var aMatch = ActiveGames.findOne({gameName: this.gameSelected(), "players.name": Meteor.userId()});
return aMatch;
}
});
ActiveGames = new Mongo.Collection('activeGames');
Player = Astro.Class({
name: 'Player',
fields: {
_id: {
type: 'string',
//immutable: true,
},
name: {
type: 'string',
validator: Validators.unique()
},
createdAt: 'date',
team: 'number',
readyUp: {
type: 'boolean',
default: false
},
},
events: {
afterInit(e) {
this.createdAt = new Date();
this._id = Random.id();
// console.log(EJSON.stringify(e.data));
}
},
});
ActiveGame = Astro.Class({
name: 'ActiveGame',
collection: ActiveGames,
fields: {
_id: 'string',
gameName: 'string',
host: 'string',
stake: 'number',
gameDetails: 'object',
startedAt: 'date',
players: {
type: 'array',
nested: 'Player',
default() {
return [];
},
validator: Validators.unique('name not unique')
}
},
});