References between collections.
meteor add shuttler:ref
var b = new Mongo.Collection('a');
b.insert({ _id: 'c' });
var c = b.findOne('c');
c.Ref(); // { id: 'c', collection: 'a' }
Helper added to all documents in all the collections. Generates an object-reference to that document.
The optional arguments are appended prefix to the keys in result object-reference.
c.Ref('_prefix'); // { '_prefix.id': 'c', '_prefix.collection': 'a' }
Find and returns the document by reference, or undefined
.
Like Shuttler.Ref
, but if ref
is a document returns it back.
Generates an object-reference.
If arguments is wrong, thrown Meteor.Error('unexpected reference')
.
- If
ref
isDocument
then usesref.Ref(prefix)
. - If
ref
isRef
then addprefix
to the keys inref
. - If
ref
isString
then useref
asid
field inRef
withoutcollection
field.
The optional arguments are appended prefix to the keys in result object-reference.
It must be a valid reference, else returns undefined
.
If ref
is object
with string id
and optional string collection
, then returns true.
Ready scheme for use with packages SimpleSchema and Collection2.
- Remove dependecie from
dburles:mongo-collection-instances
Shuttler.Ref.new
collection
field is optional- Comments