{"id":15024605,"url":"https://github.com/invertase/firebase-relationship","last_synced_at":"2025-04-19T11:57:26.422Z","repository":{"id":57236661,"uuid":"77923755","full_name":"invertase/firebase-relationship","owner":"invertase","description":"A simple Firebase Realtime Database relationship manager.","archived":false,"fork":false,"pushed_at":"2017-05-08T17:21:25.000Z","size":4,"stargazers_count":5,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-27T12:49:09.610Z","etag":null,"topics":["firebase","firebase-relationship","npm"],"latest_commit_sha":null,"homepage":"https://invertase.io","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/invertase.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-03T14:24:04.000Z","updated_at":"2021-12-07T19:23:44.000Z","dependencies_parsed_at":"2022-08-26T14:04:16.458Z","dependency_job_id":null,"html_url":"https://github.com/invertase/firebase-relationship","commit_stats":null,"previous_names":["teamfa/firebase-relationship"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/invertase%2Ffirebase-relationship","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/invertase%2Ffirebase-relationship/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/invertase%2Ffirebase-relationship/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/invertase%2Ffirebase-relationship/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/invertase","download_url":"https://codeload.github.com/invertase/firebase-relationship/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249690358,"owners_count":21311308,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["firebase","firebase-relationship","npm"],"created_at":"2024-09-24T20:00:38.200Z","updated_at":"2025-04-19T11:57:26.400Z","avatar_url":"https://github.com/invertase.png","language":"JavaScript","funding_links":["https://www.patreon.com/invertase"],"categories":[],"sub_categories":[],"readme":"# Firebase Relationship\n[![NPM version][npm-image]][npm-url]\n[![Donate](https://img.shields.io/badge/Donate-Patreon-green.svg)](https://www.patreon.com/invertase)\n\nA promise based helper to manage relationships in your Firebase Realtime Database.\n\n## Usage\n\n```bash\nnpm install firebase-relationship --save\n```\n\n```javascript\nimport Firebase from 'firebase';\nimport Relationship from 'firebase-relationship';\n\n// Create a new Firebase \u0026 Relationship instance\nconst firebase = Firebase.initializeApp({...});\nconst relationship = new Relationship('category_product');\n\n// Create a new relationship between a category (id: 123) and a product (id: abc)\nrelationship.join(firebase, 123, 'abc');\n\n// Remove the relationship\nrelationship.remove(firebase, 123, 'abc');\n```\n\n## API\n\n### - constructor(name, path)\nCreates and returns a new relationship.\n\n- **[name]** Relationship name. Must include only one underscore.\n- **[path]** Firebase path to store relationships. Defaults to 'relationship'. Must not contain leading or trailing forward slashes.\n\n\n### - join(instance, leftId, rightId, value?) : Promise\n\nCreates a two way relationship between two IDs. The 4th param is an optional value to store with the relationship (defaults to true).\n\n\n### - remove(instance, leftId, rightId) : Promise\n\nRemoves a two way relationship between two IDs.\n\n\n## Magic Methods\n\nWhen a new relationship instance is created, four magic methods are available for easy relationship querying. For example, with a \"category_product\" relationship:\n\n```javascript\n// Get products for a category\nrelationship.getCategoryProducts(firebase, categoryId).then((snapshot) =\u003e {\n  console.log('Products', snapshot.val());\n});\n\n// Get product categories\nrelationship.getProductCategories(firebase, productId).then((snapshot) =\u003e {\n  console.log('Categories', snapshot.val());\n});\n\n// you can also get the internal refs for a join\nconst refA = relationship.getCategoryProductsRef;\nconst refB = relationship.getProductCategoriesRef;\n// ... do a custom query ?\n```\n\n\u003e Each relationship name is pluralized.\n\n[npm-image]: https://img.shields.io/npm/v/firebase-relationship.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/firebase-relationship\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finvertase%2Ffirebase-relationship","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finvertase%2Ffirebase-relationship","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finvertase%2Ffirebase-relationship/lists"}