svasva / meteor-publish-with-relations

Meteor.js SmartPackage to publish associated collections at once.
162 stars 30 forks source link

support "dot" notation as foreignKey #15

Open dohomi opened 10 years ago

dohomi commented 10 years ago

Hi, Is it planned to support dotted notation for foreign keys like `key: '_audit.ownerId'``? Would make the use of the plugin more flexible. Cheers Dominic

Multiply commented 10 years ago

@dohomi Could you try https://github.com/Multiply/meteor-publish-with-relations/commit/6fdf6bce39ce8fa12a39799b63f394c0c159ce32 with your project, and see if it works as intended?

Put the following in your smart.json

{
  "packages": {

    "publish-with-relations": {
      "git": "https://github.com/Multiply/meteor-publish-with-relations.git",
      "branch": "issue-15"
    }

  }
}
dohomi commented 10 years ago

Hello,

I just got back to this issue and tried with following code:

    Meteor.publishWithRelations({
        handle: this,
        collection:Posts,
        filter: filter,
        options: options,
        mappings: [
            {
                key: 'ownerId',
                collection: Meteor.users,
                options: {fields: {profile: 1}},
                mappings: [
                    {
                        key: 'profile.imageId',
                        collection:ProfileImagesFS
                    }
                ]
            }
        ]
    });

But this doesn't subscribes to the ProfileImagesFS.

Multiply commented 10 years ago

@dohomi I am running this perfectly fine with the above code. Are you sure you're running my version?

Meteor.publishWithRelations
    handle     : @
    collection : chatMessages
    filter     : 
        room : id
    options :
        sort :
            createdAt : -1
        limit : 30
    mappings : [
        key        : 'user'
        collection : Meteor.users
    ,
        key        : 'mention.users'
        collection : Meteor.users
    ]