Comments (10)
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.
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.
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.
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.
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.
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.
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.
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.
@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.
Thanks I will try.
from cottz-publish-relations.
Related Issues (16)
- Package description identical to cottz-publish HOT 2
- Changing filters reactively HOT 3
- How handle array of objects in collection? HOT 2
- this.join unexpected behaviour HOT 7
- What are the advantages over reywood:publish-composite package HOT 5
- Add support for server minimongo HOT 3
- Is 'this.ready()' obligatory? HOT 4
- the parent doc is removed, the related children doc is not removed. HOT 5
- seems broken HOT 1
- Help Plz: Filter/remove some documents from a this.cursor() - call? HOT 4
- Need help getting started HOT 6
- Crossbar problem! HOT 4
- How to get doc for relations fields? HOT 4
- Please example how to "return [cursor1, cursor2, cursor3];" HOT 2
- Trying this.listen example HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cottz-publish-relations.