This is supposed to be a simple many to many relationships in meteor but I must be missing something because i cannot get it to work.
I have a Collection called reblog and in it is an array of integers called descovered
see image
I have a second collection called posts which is a collection of posts, and these posts have an id. take a look at the second image
I want to create a many to many relationships between the posts and the reblog collection. i.e, I want to match the integer
descovered: 9
from the reblog collection, with:
id: 9
from the posts collection so that I can display only the posts matched from the reblog collection. This of course will allow me to display the title of the post and other attributes.
This is my js
Template.reblogging.helpers({
descovered() {
var id = FlowRouter.getParam('_id');
//fetch the reblog collection contents
var rebloged = reblog.find().fetch();
//log below is showing that the fetch is successful because i can see the objects fetched in console
console.log(rebloged);
//create the relationship between the posts collection and the reblog collection
var reblogger = posts.find({
id: {
$in: rebloged
}
}).fetch();
//nothing is showing with the log below, so something is going wrong with the line above?
console.log(reblogger);
return reblogger
}
});
I must be missing something because this seems a pretty straightforward thing but it's not woring
And my HTML is like this
<template name="reblogging">
{{#each descovered }}
<ul class="">
<li>
<h5 class="">{{title.rendered}}</h5>
</li>
</ul>
{{/each}}
</template>
As it turns out, the matching was accurate, however, the data from
reblog
collection needed to be treated with REGEX to get rid of everything else apart from the values I needed, then turn them into an array, this is the final code that worked. leaving it here, Hopefully, it will help someone in the future.