Firebase Relationship
A promise based helper to manage relationships in your Firebase Realtime Database.
Usage
npm install firebase-relationship --save
;; // Create a new Firebase & Relationship instanceconst firebase = Firebase;const relationship = 'category_product'; // Create a new relationship between a category (id: 123) and a product (id: abc)relationship; // Remove the relationshiprelationship;
API
constructor(name, path)
Creates and returns a new relationship.
- [name] Relationship name. Must include only one underscore.
- [path] Firebase path to store relationships. Defaults to 'relationship'. Must not contain leading or trailing forward slashes.
join(instance, leftId, rightId, ?value)
Creates a two way relationship between two IDs. The 4th param is an optional value to store with the relationship (defaults to true).
remove(instance, leftId, rightId)
Removes a two way relationship between two IDs.
Magic Methods
When a new relationship instance is created, two magic methods are available for easy relationship querying. For example, with a "category_product" relationship:
// Get products for a categoryrelationship; // Get product categoriesrelationship;
Each relationship name is pluralized.