Lepozepo / meteor-publish-with-relations

Meteor.js SmartPackage to publish associated collections at once.
https://atmospherejs.com/lepozepo/publish-with-relations
11 stars 4 forks source link

FR: Support multiple key fields #4

Open lorensr opened 9 years ago

lorensr commented 9 years ago

I currently can't do a mapping with two keys, eg

Transfer
  from: uid1
  to: uid2

mapping: [
  foreign_key: 'from'
  foreign_key: 'to'
  collection: Meteor.users
]

you have to duplicate the uids into an array, eg:

Transfer
  from: uid1
  to: uid2
  users: [uid1, uid2]

Perhaps this is because having multiple fields would not be performant compared to a single array field, in which case I withdraw the FR :)

Lepozepo commented 9 years ago

Well you definitely can't have 2 foreign_key lol. I think you might have misunderstood the way you use it. The correct way is foreign_key:"users" and you're done.

lorensr commented 9 years ago

Right, that's what you do when the schema has users, but it would be nice if the schema didn't need the users array, and the package was modified to work w/ 2 foreign_keys or 2 keys.

Lepozepo commented 9 years ago

Ah, I get it now, lol. That might not be too difficult to patch in but performance could be affected since you would end up querying per key vs a single array query.

lorensr commented 9 years ago

Okay, so it would just be in effect doing this:

    mappings: [
      foreign_key: 'from'
      collection: Meteor.users
    , 
      foreign_key: 'to'
      collection: Meteor.users
   ]

(which works currently)

And doing that is not performant as using an array.

Lepozepo commented 9 years ago

Using an array will increase performance for sure but both will perform well.