{"id":21428634,"url":"https://github.com/jaynetics/denormalize_fields","last_synced_at":"2026-05-18T03:34:37.307Z","repository":{"id":39691160,"uuid":"240241402","full_name":"jaynetics/denormalize_fields","owner":"jaynetics","description":"Denormalizes ActiveRecord fields from one record to another","archived":false,"fork":false,"pushed_at":"2023-07-23T05:32:19.000Z","size":57,"stargazers_count":0,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-27T22:09:01.843Z","etag":null,"topics":["activerecord","denormalization","rails"],"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/jaynetics.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","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":"2020-02-13T11:11:23.000Z","updated_at":"2021-12-30T22:11:12.000Z","dependencies_parsed_at":"2025-08-26T03:34:12.410Z","dependency_job_id":"21b4ba6e-0f6e-4e66-b7b9-ad2db802c0e8","html_url":"https://github.com/jaynetics/denormalize_fields","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/jaynetics/denormalize_fields","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaynetics%2Fdenormalize_fields","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaynetics%2Fdenormalize_fields/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaynetics%2Fdenormalize_fields/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaynetics%2Fdenormalize_fields/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaynetics","download_url":"https://codeload.github.com/jaynetics/denormalize_fields/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaynetics%2Fdenormalize_fields/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33163765,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-17T22:39:12.733Z","status":"online","status_checked_at":"2026-05-18T02:00:06.436Z","response_time":71,"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":["activerecord","denormalization","rails"],"created_at":"2024-11-22T22:14:08.108Z","updated_at":"2026-05-18T03:34:37.289Z","avatar_url":"https://github.com/jaynetics.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DenormalizeFields\n\n[![Gem Version](https://badge.fury.io/rb/denormalize_fields.svg)](http://badge.fury.io/rb/denormalize_fields)\n[![Build Status](https://github.com/jaynetics/denormalize_fields/workflows/tests/badge.svg)](https://github.com/jaynetics/denormalize_fields/actions)\n\nThis gem adds a `denormalize` option to ActiveRecord relation definitions, so that updates on one record are forwarded to its dependent records.\n\nTested on Rails 7, but should work down to Rails 4.1.\n\n## Installation\n\nAdd, install or require `denormalize_fields`.\n\n## Usage\n\nEither:\n\n```ruby\nclass User \u003c ApplicationRecord\n  has_many :posts, denormalize: { fields: %i[first_name last_name] }\nend\n```\n\nOr:\n\n```ruby\nDenormalizeFields.denormalize(\n  fields: %i[first_name last_name],\n  from:   User,\n  onto:   :posts,\n)\n```\n\nResulting behavior:\n\n```ruby\nUser.first.posts.pluck(:first_name) # =\u003e ['Igor', 'Igor']\nUser.first.update!(first_name: 'Wanja')\nUser.first.posts.pluck(:first_name) # =\u003e ['Wanja', 'Wanja']\n```\n\nAny validation errors in denormalized fields of dependent records are bubbled up to the source record.\n\nThere is also a `prefix` option:\n\n```ruby\n# assuming there is Rapper#name and Car#owner_name\nclass Rapper \u003c ApplicationRecord\n  has_many :cars, denormalize: { fields: :name, prefix: :owner_ } }\nend\n```\n\nAlternatively `fields` also accepts a `Hash` to map to other fields on the related record:\n\n```ruby\n# assuming there is Rapper#name and Car#owner\nclass Rapper \u003c ApplicationRecord\n  has_many :cars, denormalize: { fields: { name: :owner } }\nend\n\n# multiple fields can be mapped to one, their values will be joined with \" \"\nclass Rapper \u003c ApplicationRecord\n  has_many :cars, denormalize: { fields: { %i[first_name last_name] =\u003e :owner } }\nend\n```\n\nConditional denormalization is also supported:\n\n```ruby\nclass Blog \u003c ApplicationRecord\n  # don't remove topic from posts when it is removed from blog\n  has_many :posts, denormalize: { fields: :topic, if: :topic? }\nend\n```\n\n## Caveats\n\n- only works with fields that are in the database, no virtual attributes etc.\n- does not work with `has_and_belongs_to_many` associations\n- is based on `ActiveRecord` callbacks, so does not work for `#update_column` etc.\n- does no denormalization when related records are first created / connected\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/jaynetics/denormalize_fields.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Comparison with similar projects\n\nMost of these have not been updated in years. Let me know if there is any cool new stuff.\n\n- https://github.com/ursm/activerecord-denormalize\n  - similar goal\n  - runs custom SQL, so does not work with all DBs\n  - skips validations of related records\n  - only supports `has_many` relations, not `has_one` or `belongs_to`\n- https://github.com/bebanjo/persistize\n  - for denormalization onto the *same* record or owner record only\n- https://github.com/ignu/denormalize-field\n  - for denormalization onto the *same* record or owner record only\n  - postgres only\n- https://github.com/logandk/mongoid_denormalize\n  - similar goal\n  - mongoid only\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaynetics%2Fdenormalize_fields","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaynetics%2Fdenormalize_fields","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaynetics%2Fdenormalize_fields/lists"}