Skip to content

hypno2000/meteor-publish-with-relations

 
 

Repository files navigation

This package is fork of lepozepo:publish-with-relations, the changes so far are:

  • Objects support. Allowing keys to be deeper than just in root document.
  • Fixed a bug where you could not have two relations referring to same collection in one collection. Also affected a scenario where u have document that has two different list of sub-documents and you wanted to publish both of these. For example a document blogPost has list of comments and list of images in separate collections.

Orignal readme

BREAKING CHANGES:

  • key is now foreign_key
  • reverse does not exist anymore
  • Migrating:
    • If reverse:false then replace key:yourkey with foreign_key:yourkey

This package is an updated version of tmeasday:publish-with-relations the key difference is support for arrays, nested arrays, a friendlier interface, and some bug fixes

API

Meteor.publishWithRelations(ops) (SERVER SIDE)

Used inside a Meteor.publish() function to define relations.

ops.handle: (REQUIRED)
Must always be this

ops.collection: (REQUIRED)
The anchor collection from which relations will be made.

ops.filter: (OPTIONAL)
The object that filters the collection. This is the equivalent to filter in collection.find(filter).

ops.options: (OPTIONAL)
The object that sorts and limits the collection. This is the equivalent to options in collection.find(filter,options).

ops.mappings: (OPTIONAL)
An array of objects that maps relationships between collections using foreign_key and key

ops.mappings[].collection: (REQUIRED)
Defines the collection that will be associated.

_ops.mappings[].foreign_key: (DEFAULT:"id")
Defines the key to associate with at the parent collection.

_ops.mappings[].key: (DEFAULT:"id")
Defines the key to associate with at the current collection.

ops.mappings[].filter: (OPTIONAL)
The object that filters the collection. This is the equivalent to filter in collection.find(filter).

ops.mappings[].options: (OPTIONAL)
The object that sorts and limits the collection. This is the equivalent to options in collection.find(filter,options).

Sample

Meteor.publish "things", ->
	Meteor.publishWithRelations
		handle:this
		collection:Things
		mappings:[
			{
				foreign_key:"sub_things>deep_things>deep_thing"
				collection:DeepThings
			}
			{
				foreign_key:"sub_things>sub_thing"
				collection:SubThings
			}
			{
				foreign_key:"other_thing"
				collection:OtherThings
			}
			{
				key:"thing"
				collection:ReverseThings
			}
		]

This will publish all Things and their respective DeepThings, SubThings, OtherThings, and ReverseThings

IMPORTANT: When an association is broken, the package will stop all subscriptions to all broken associations but will not remove the association from the client. This means updates to the object with the broken association will not be recorded BUT the object will persist on the client. New associations will be published as expected. (This should not have an impact unless you are doing something with total published counts).

About

Meteor.js SmartPackage to publish associated collections at once.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • CoffeeScript 94.0%
  • JavaScript 6.0%