{"action":"created","issue":{"url":"https://api.github.com/repos/englue/meteor-publish-composite/issues/59","labels_url":"https://api.github.com/repos/englue/meteor-publish-composite/issues/59/labels{/name}","comments_url":"https://api.github.com/repos/englue/meteor-publish-composite/issues/59/comments","events_url":"https://api.github.com/repos/englue/meteor-publish-composite/issues/59/events","html_url":"https://github.com/englue/meteor-publish-composite/issues/59","id":106311865,"number":59,"title":"Invalidate child cursors if their parent changes.","user":{"login":"SteveFortune","id":4347230,"avatar_url":"https://avatars.githubusercontent.com/u/4347230?v=3","gravatar_id":"","url":"https://api.github.com/users/SteveFortune","html_url":"https://github.com/SteveFortune","followers_url":"https://api.github.com/users/SteveFortune/followers","following_url":"https://api.github.com/users/SteveFortune/following{/other_user}","gists_url":"https://api.github.com/users/SteveFortune/gists{/gist_id}","starred_url":"https://api.github.com/users/SteveFortune/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SteveFortune/subscriptions","organizations_url":"https://api.github.com/users/SteveFortune/orgs","repos_url":"https://api.github.com/users/SteveFortune/repos","events_url":"https://api.github.com/users/SteveFortune/events{/privacy}","received_events_url":"https://api.github.com/users/SteveFortune/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-14T10:14:53Z","updated_at":"2015-09-14T10:46:33Z","closed_at":"2015-09-14T10:46:33Z","body":"We have a model where users have a many-to-many relationship with organisations. We're using a joining collection called 'Memberships' to model the relationship: a membership has a `userId`, an `_orgId` and various other properties relating to the user's permissions within that organisation.\r\n\r\nI've started using `publishComposite` to make the following available to the user:\r\n\r\n- their (active) memberships,\r\n- the organisations that they are a member of, and\r\n- the other users in the organisations that they are a member of.\r\n\r\n```Javascript\r\nMeteor.publishComposite(\"memberships\", {\r\n  find: function() {\r\n    return Memberships.find({\r\n      isActive: true,\r\n      ... etc\r\n    });\r\n  },\r\n  children: [\r\n    {\r\n      find: function(mem) {\r\n        return Meteor.users.find(mem.userId);\r\n      }\r\n    },\r\n    {\r\n      find: function(mem) {\r\n        return Organisations.find(mem._orgId);\r\n      }\r\n    }\r\n  ]\r\n});\r\n```\r\n\r\nThe problem we have is that memberships might be de-activated at any time by the organisation administrator. In this model, when a membership becomes inactive, the users and organisations that the user _used_ to have access to should be removed from the publication.\r\n\r\nIt seems as though the cursors from the `children` array aren't updated when a document is added or removed to/from the top-level cursor - `Memberships.find({...})`."},"comment":{"url":"https://api.github.com/repos/englue/meteor-publish-composite/issues/comments/140035475","html_url":"https://github.com/englue/meteor-publish-composite/issues/59#issuecomment-140035475","issue_url":"https://api.github.com/repos/englue/meteor-publish-composite/issues/59","id":140035475,"user":{"login":"SteveFortune","id":4347230,"avatar_url":"https://avatars.githubusercontent.com/u/4347230?v=3","gravatar_id":"","url":"https://api.github.com/users/SteveFortune","html_url":"https://github.com/SteveFortune","followers_url":"https://api.github.com/users/SteveFortune/followers","following_url":"https://api.github.com/users/SteveFortune/following{/other_user}","gists_url":"https://api.github.com/users/SteveFortune/gists{/gist_id}","starred_url":"https://api.github.com/users/SteveFortune/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SteveFortune/subscriptions","organizations_url":"https://api.github.com/users/SteveFortune/orgs","repos_url":"https://api.github.com/users/SteveFortune/repos","events_url":"https://api.github.com/users/SteveFortune/events{/privacy}","received_events_url":"https://api.github.com/users/SteveFortune/received_events","type":"User","site_admin":false},"created_at":"2015-09-14T10:46:33Z","updated_at":"2015-09-14T10:46:33Z","body":"Looks like `publishComposite` does actually take care of this for you, by bad. \r\n\r\nI had some additional parameters being appended to the `Memberships.find` query in a hook, which meant that it expanded to something like:\r\n\r\n```Javascript\r\n{\r\n    isActive: true,\r\n    _orgId: { $in: {...} }\r\n}\r\n```"}}