{"id":20630652,"url":"https://github.com/brookisme/familyable","last_synced_at":"2026-04-22T04:33:43.939Z","repository":{"id":71617189,"uuid":"31026186","full_name":"brookisme/familyable","owner":"brookisme","description":"A gem for creating self-referential parent child relationships on a model","archived":false,"fork":false,"pushed_at":"2017-01-06T21:09:13.000Z","size":22,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-19T12:27:39.883Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brookisme.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-02-19T17:04:45.000Z","updated_at":"2017-01-06T21:09:15.000Z","dependencies_parsed_at":"2023-02-23T20:45:19.102Z","dependency_job_id":null,"html_url":"https://github.com/brookisme/familyable","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/brookisme/familyable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brookisme%2Ffamilyable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brookisme%2Ffamilyable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brookisme%2Ffamilyable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brookisme%2Ffamilyable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brookisme","download_url":"https://codeload.github.com/brookisme/familyable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brookisme%2Ffamilyable/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32121020,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-22T00:31:26.853Z","status":"online","status_checked_at":"2026-04-22T02:00:05.693Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-16T14:09:08.519Z","updated_at":"2026-04-22T04:33:43.933Z","avatar_url":"https://github.com/brookisme.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Familyable\n\nThis gem makes creating self-referential parent child relationships on a model easy. So for a `Person` model you have `person.parent` and `person.children` where the parent and children are also people.\n\nYou also get the following instance methods:\n\n* descendents\n* elders\n* siblings\n* family    \n* master  *- the 'oldest' in the family*\n\nand the class method:\n\n* masters *- everyone without a parent*\n\nStandard stuff I know but...\n##### Everyone of the methods above works with a single call to the data base!!!\n\nThis is a **[huge](https://github.com/brookisme/familyable-testapp)** performance gain.  In fact, being able build the above methods with a single database call was the entire motivation for gemifiying something that otherwise was entirely straight forward.  It should be noted that this was built the day after reading [this](http://hashrocket.com/blog/posts/recursive-sql-in-activerecord).\n\n-----------------------------------------------------------\n\n##### WARNING: This project is still in development\n    [x] create relationship concern\n    [X] create generators for relationship models\n    [X] check that it works with engines\n    [ ] add generation handling\n    [ ] generate data for testapp\n    [ ] tests tests tests\n    [ ] refactor concern\n    [ ] add servents methods (class and instance)?\n\n\n### Requirments\n\nYou must be using a postgres data base... thats where the single-db-query magic happens.\n\n### Installation\n\nNote: use with caution. This gem is still in developement\n\n*Gemfile*\n```\ngem 'familyable'\n```\n```\n$  bundle install\n```\n\n### Usage\n\n-----------------------------------------------------------\n\nExample: Adding Relationships to an existing `Person` model:\n\n##### Step 1: Generate Relationship Model\n\n```\n$  bundle exec rails g familyable:relationships Person\n$  bundle exec rake db:migrate\n```\n\n##### Step 2: Add Relationships Concern to Model\n\n_app/models/person.rb_\n```ruby\nclass Person \u003c ActiveRecord::Base\n    include Familyable::Relationships\n    ...\nend\n```\n\nFor use inside of rails engines see [this](#rails_engines) note.\n\n##### Step 3: Add Generation Handling \n\nUntil we create a generator for this step you need to add a call back to the relationships model to handle setting `person.generation`\n\n_app/models/person\\_relationship.rb_\n```ruby\n#\n# generation handling \n#\n    before_save :update_generation\n\nprivate\n\n    def update_generation\n      child.set_generation\n      child.save\n    end\n```\n\n##### Step 4: You're done! start coding\n\nquick note: all the instance methods above (accept for master) take an optional parameter *include\\_self=false*.  it does what you exactly what you think.\n\n```ruby\nPerson.masters\nperson.master\nperson.descendents\nperson.descendents(true)\n...\n```\n\n-----------------------------------------------------------\n\u003ca name=\"rails_engines\"\u003e\u003c/a\u003e\n\n**Rails Engine Note**: For use with rails engines use the full model name from the the root of your Engine directory and require it in your engine.rb\n\n```\n$  bundle exec rails g familyable:relationships EngineName::Person\n```\n\n*lib/engine_name/engine.rb*\n```ruby\n...\nrequire 'familyable'\nmodule EngineName\n  class Engine \u003c ::Rails::Engine\n  ...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrookisme%2Ffamilyable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrookisme%2Ffamilyable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrookisme%2Ffamilyable/lists"}