perak / meteor-joins

Collection joins for Meteor
77 stars 7 forks source link

How to join strings array with ids? #10

Open livimonte opened 8 years ago

livimonte commented 8 years ago

Hi,

I have a tag field with select2, user can select multiple tags and i store the array of ids.

I want to join the values of tags, any suggestions on how I can do this?

I used the Qualities Collection to illustrate Tags:

var Companies = new Mongo.Collection("companies");
var Qualities = new Mongo.Collection("qualities");
var Employees = new Mongo.Collection("employees");

//Companies
{
  _id: "CQKDzmqmQXGhsC6PG",
  name: "Acme"
}

//Qualities
{
  _id: "AAKDzmqmQXGhsC6AA",
  name: "Amazing"
}
{
  _id: "BBKDzmqmQXGhsC6BB",
  name: "Awesome"
}

//Employees
{
  _id: "dySSKA25pCtKjo5uA",
  name: "Jimi Hendrix",
  companyId: "CQKDzmqmQXGhsC6PG",
  qualitiesIDs: [
    'AAKDzmqmQXGhsC6AA',
    'BBKDzmqmQXGhsC6BB'
  ]
}

//Join Company - OK!
Employees.join(Companies, "companyId", "company", ["name"]);

//I get this - OK!
{
  _id: "dySSKA25pCtKjo5uA",
  name: "Jimi Hendrix",
  companyId: "CQKDzmqmQXGhsC6PG",
  company: {
    name: "Acme"
  },
  qualitiesIDs: [
    'AAKDzmqmQXGhsC6AA',
    'BBKDzmqmQXGhsC6BB'
  ]
}

Employees.join(Qualities, "qualitiesIDs", "qualities", []);

//How i can get this result?

{
  _id: "dySSKA25pCtKjo5uA",
  name: "Jimi Hendrix",
  companyId: "CQKDzmqmQXGhsC6PG",
  company: {
    name: "Acme"
  }
  qualitiesIDs: [
    'AAKDzmqmQXGhsC6AA',
    'BBKDzmqmQXGhsC6BB'
  ]
  qualities: [
    {
      _id: "AAKDzmqmQXGhsC6AA",
      name: "Amazing"
    },
    {
      _id: "BBKDzmqmQXGhsC6BB",
      name: "Awesome"
    }
  ]
}
raza2022 commented 5 years ago

@livimonte have you ever found the solutions? please share, as my case almost identical