{"id":18656554,"url":"https://github.com/zendesk/active_record_inherit_assoc","last_synced_at":"2025-05-10T19:45:43.465Z","repository":{"id":553491,"uuid":"2270679","full_name":"zendesk/active_record_inherit_assoc","owner":"zendesk","description":"Attribute inheritance for AR associations","archived":false,"fork":false,"pushed_at":"2025-01-20T08:54:19.000Z","size":113,"stargazers_count":11,"open_issues_count":1,"forks_count":4,"subscribers_count":422,"default_branch":"main","last_synced_at":"2025-05-10T19:45:36.304Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zendesk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"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,"zenodo":null}},"created_at":"2011-08-25T21:19:30.000Z","updated_at":"2025-01-20T08:54:19.000Z","dependencies_parsed_at":"2024-01-08T15:09:26.497Z","dependency_job_id":"e3082b67-6c37-4f7e-a2d3-796424e6c335","html_url":"https://github.com/zendesk/active_record_inherit_assoc","commit_stats":{"total_commits":112,"total_committers":17,"mean_commits":6.588235294117647,"dds":0.8035714285714286,"last_synced_commit":"871ca6f992895bde5707860c7276fe706c9d1a4b"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zendesk%2Factive_record_inherit_assoc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zendesk%2Factive_record_inherit_assoc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zendesk%2Factive_record_inherit_assoc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zendesk%2Factive_record_inherit_assoc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zendesk","download_url":"https://codeload.github.com/zendesk/active_record_inherit_assoc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253474091,"owners_count":21914223,"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":[],"created_at":"2024-11-07T07:23:57.503Z","updated_at":"2025-05-10T19:45:43.434Z","avatar_url":"https://github.com/zendesk.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ActiveRecord association inheritance\n\n - Makes models inherit specified attributes from an association.\n - Scope queries by inherited attributes\n\n## Install\n\n```\ngem install active_record_inherit_assoc\n```\n\n## Usage\n\n### Filling inherited attributes on initialization:\n```Ruby\n# parent_name - The Symbol name of the parent association.\n# options     - The Hash options to use:\n#               :attr - A Symbol or an Array of Symbol names of the attributes\n#                       that should be inherited from the parent association.\n#\nclass Post \u003c ActiveRecord::Base\n  belongs_to :category\n  inherits_from :category, attr: :account\nend\n```\n\n### Scoping queries\n\n```Ruby\nclass Post \u003c ActiveRecord::Base\n  has_many :categories, inherit: :account_id\nend\n\npost = Post.first\npost.categories.build.account_id == post.account_id # fills attribute on new objects\npost.categories.to_sql # adds inherited attributes to queries\n```\n\nThis is similar to adding a scope `{ |record| where(account_id: record.account_id) }`,\nbut also allows to do `Post.all.includes(:categories)` to work by filtering preloaded records.\nThis will not use the attribute to query, so it might use a different index and find more than neccessary records.\n\n#### Allowed list of values (inherit_allowed_list)\n\nIn some occasions, there are values that we don't want to filter out, even if they don't correspond to the inherited one.\nFollowing the previous Post example, this could happen if we have a universal \"system\" category belonging to no account, one that we associated to all the posts that have no other category. A way to keep this category (assuming that it has the account_id `-1`) would look like this:\n\n```Ruby\nclass Post \u003c ActiveRecord::Base\n  has_many :categories, inherit: :account_id, inherit_allowed_list: [-1]\nend\n```\n\n## Copyright and license\n\nCopyright 2022 Zendesk\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under the\nLicense is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and limitations under the License.\n\n## Author\nBen Osheroff \u003cben@gimbo.net\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzendesk%2Factive_record_inherit_assoc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzendesk%2Factive_record_inherit_assoc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzendesk%2Factive_record_inherit_assoc/lists"}