Skip to content

huevoncito/meteor-publish-with-relations

 
 

Repository files navigation

__This package is fork of hypno2000:publish-with-relations. This fork fixes a minor bug that threw an error when a published results set changed. Everything else is exactly the same as @hypno2000's version

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 91.1%
  • JavaScript 8.9%