Git Product home page Git Product logo

Comments (10)

lfades avatar lfades commented on July 28, 2024

so I understood you want to publish one or more enrollments and publish their claims

Meteor.publishRelations('enrollments', function (enrollment) {
    let cursor = Enrollments.find({childrenName: enrollment}, {sort: {childrenName: 1}});

    this.cursor(cursor, function (id, doc) {
        this.cursor(Claims.find({_id: {$in: [doc.childrenName, doc.children2, doc.children3]}}));
    });

    return this.ready();
});

if the code is incorrect or not let me know

from cottz-publish-relations.

Ajaxsoap avatar Ajaxsoap commented on July 28, 2024

Thanks @goluis for your time!

Yeah, to make it simple, on claims collection I should have fullName(enrollmentId) and it's corresponding childrenName from enrollments collection.

Desired scenario, use case, on my claims form, i have a enrollmentId dropdown list, since the claim is for the dependent children, based on the chosen enrollmentId, on childrenName dropdown list it should only be the children of the chosen enrollmentId is available. The selection childrenName should be from the same document (same _id).

My current setup is that all the childrenName from other documents is being passed :(

from cottz-publish-relations.

lfades avatar lfades commented on July 28, 2024

It is quite likely that I still don't understand

the Claims form show all the Enrollments, so you have a publication like this I guess

Meteor.publish(function () {
  return Enrollments.find({}, {sort: {fullName: 1}})
})

the user selects an Enrollment and then subscribe to his Claims

Meteor.publish('enrollments', function (childrenName) {
    // this is the part I do not understand
    return Claims.find({childrenName: childrenName})
})

from cottz-publish-relations.

Ajaxsoap avatar Ajaxsoap commented on July 28, 2024

The user which is one of the staff in an insurance company, enrolled (create enrollment) a certain John Doe (fullName) with his 3 kids(children), assuming this John Doe filed a claim (claims collection) for his kid(children from Enrollments collection). The user will create a claim selecting John Doe as the principal and select John Doe's kid as the dependent.

Given the context of John Doe, the children selection is limited to only his child not all children from other enrollee. Am I making any sense?

This is my current publication:

Meteor.publish(function () {
  return Enrollments.find();
})

on creating a claim, the user subscribe to Enrollments:

Meteor.publish('claimEnrollment', function() {
   // fields fullName, children
   return Enrollments.find({},{fields: {fullName: 1, childrenName: 1, children2: 1}});
});

I'm having a hard time making this to work, even using reactiveVar to set and ``get` the id of John Doe, the selection is always populated with all the child on the collection.

from cottz-publish-relations.

lfades avatar lfades commented on July 28, 2024

the following publication should return all Enrollments or a single enrollment with his children Claims

Meteor.publishRelations('test', function (fullName) {
  check(fullName, Match.Optional(String));

  if (!fullName)
    return Enrollments.find();

  // {fullName} = {fullName: fullName}
  let cursor = Enrollments.find({fullName}, {fields: fullName: 1, childrenName: 1, children2: 1}})

  this.cursor(cursor, function (id, doc) {
    this.cursor(Claims.find({
      principal: fullName,
      dependent: {$in: [doc.childrenName, doc.children2]}
    }))
  })

  return this.ready()
})

I'm closer to the solution?

from cottz-publish-relations.

Ajaxsoap avatar Ajaxsoap commented on July 28, 2024

Thanks so much @goluis for sharing your expertise!

I think this will work, as I can see it's in the document level :)

I will try this and get back to you!

👍

from cottz-publish-relations.

lfades avatar lfades commented on July 28, 2024

Importantly: PublishRelations uses a basic observeChanges. doc is only the complete document when sending the first time, then he only has the changes, is likely to lose reactivity when the document change, luckily there are many quick ways to fix it.

This method is quite good but is somewhat complex

let children = [];
this.cursor(cursor, function (id, doc) {
  if (doc.childrenName || doc.children2) {
    if (doc.childrenName)
      children[0] = doc.childrenName
    if (doc.children2)
      children[1] = doc.children2

    this.cursor(Claims.find({
      principal: fullName,
      dependent: {$in: children}
    }))
  }
})

using this.join

let children = this.join(Claims)
children.selector = names => {principal: fullName, dependent: names}
/*children.selector = function (names) {
  return {
    principal: fullName,
    dependent: names
  }
}*/
this.cursor(cursor, function (id, doc) {
  children.push(doc.childrenName, doc.children2)
})
children.send()

If the children never change this would be the ideal method

this.cursor(cursor, {
  added (id, doc) {
    this.cursor(Claims.find({
      principal: fullName,
      dependent: {$in: [doc.childrenName, doc.children2]}
    }))
  }
})

I recommend you see the last part of the documentation, it has a lot of useful information ^^

from cottz-publish-relations.

thearabbit avatar thearabbit commented on July 28, 2024

Excuse me, I don't understand how to get doc of Claims.
(We can get it automatic in Enrollments or not)

from cottz-publish-relations.

lfades avatar lfades commented on July 28, 2024

@thearabbit the package makes relationships, but cursor sends all documents to their respective collection, to pick up the document use a callback:

// send all users
this.cursor(Meteor.users.find()); 

// send all users with a new key in the document
this.cursor(Meteor.users.find(), function (id, doc) {
  doc.something = true;
});

from cottz-publish-relations.

thearabbit avatar thearabbit commented on July 28, 2024

Thanks I will try.

from cottz-publish-relations.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.