Meteor-Community-Packages / meteor-publish-composite

Meteor.publishComposite provides a flexible way to publish a set of related documents from various collections using a reactive join
https://atmospherejs.com/reywood/publish-composite
MIT License
554 stars 58 forks source link

Angular-Meteor Meteor.publishComposite #90

Closed HectorRPL closed 7 years ago

HectorRPL commented 7 years ago

Hello, thanks for read

When running helper brings values are stored in the variable verCandidatos.postulados. Once I get me the information I need to get a document that is linked (using the function ng-init="candidato = la postulado.candidato()) wich runs on the helper from file: collection.js. Sometimes the html shows the properties: {{candidato.nombre}}, {{candidato.apellidos}} and {{candidato.sexo}} correctly, and sometimes appear empty, why?

The information is being obtained, because the ng-repeat works and shows elements. Is very strange, like a bug or something. How is possible that behavior?

Below is the publishComposite(), collection.js, html and js client

html client my-app/imports/ui/components/vacantes/verCandidatos/verCandidatos.html

<div ng-repeat="postulado in verCandidatos.postulados">
    <div ng-init="candidato = postulado.candidato();">
          {{candidato.nombre}} 
          {{candidato.apellidos}}
          {{candidato.sexo}}            
    </div>
</div>

js in client my-app/imports/ui\components/vacantes/verCandidatos/verCandidatos.js

imports ...

class VerCandidatos {
    constructor($scope, $reactive, $stateParams) {
        'ngInject';
        $reactive(this).attach($scope);
        this.vacanteId = $stateParams.vacanteId;
        this.subscribe('vacantes.candidatosOseleccionados', ()=> [{vacanteId: this.vacanteId}, {estado: 1}]);
        this.helpers({
            postulados (){
                return Postulaciones.find();
            }
        });

    }
}

collection.js my-app/imports/api/postulaciones/collection.js

imports...

export const Postulaciones = new Mongo.Collection('postulaciones');

Postulaciones.deny({...});

Postulaciones.helpers({
    candidato(){
        return Candidatos.findOne({_id: this.candidatoId});
  }  
});

publish.js: my-app/imports/api/vacantes/server/publish.js

imports...

if (Meteor.isServer) {
    Meteor.publishComposite('vacantes.candidatosOseleccionados', function (vacanteId, estado) {
        const selector = {$and: [estado, vacanteId]};
            return {
                find: function () {
                    return Postulaciones.find(selector);
                },
                children: [
                    {
                        find: function (postulacion) {
                            return Candidatos.find({_id: postulacion.candidatoId}, {
                                fields: {
                                    nombre: 1,
                                    apellidos: 1,
                                    sexo: 1,
                                }
                            });
                        }
                    }
                ]
            };
    });
}

Any ideas?

reywood commented 7 years ago

Nothing comes to mind as to why it wouldn't work. Can't comment further with out seeing a meteor app the demonstrates the issue. If you like, create a github repo with a sample project. Closing for now.