{"id":14955975,"url":"https://github.com/chaudhary/mongoid-denormalization","last_synced_at":"2026-01-29T03:11:38.393Z","repository":{"id":56884361,"uuid":"114510368","full_name":"chaudhary/mongoid-denormalization","owner":"chaudhary","description":"Helper module for denormalizing association attributes in Mongoid models \u0026 embedded models.","archived":false,"fork":false,"pushed_at":"2023-01-31T00:50:28.000Z","size":57,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-29T14:18:12.635Z","etag":null,"topics":["denormalization","mongoid","mongoid-plugin","rails","rails5","rubygem"],"latest_commit_sha":null,"homepage":"","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/chaudhary.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-17T04:52:45.000Z","updated_at":"2020-11-05T05:33:54.000Z","dependencies_parsed_at":"2023-02-18T01:55:27.670Z","dependency_job_id":null,"html_url":"https://github.com/chaudhary/mongoid-denormalization","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaudhary%2Fmongoid-denormalization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaudhary%2Fmongoid-denormalization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaudhary%2Fmongoid-denormalization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaudhary%2Fmongoid-denormalization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chaudhary","download_url":"https://codeload.github.com/chaudhary/mongoid-denormalization/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247834079,"owners_count":21003909,"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":["denormalization","mongoid","mongoid-plugin","rails","rails5","rubygem"],"created_at":"2024-09-24T13:12:06.621Z","updated_at":"2026-01-29T03:11:33.351Z","avatar_url":"https://github.com/chaudhary.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mongoid::Denormalization\n\nHelper module for denormalizing association attributes in Mongoid models \u0026 embedded models.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'mongoid-denormalization'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install mongoid-denormalization\n\n## Usage\n\nIn your model:\n```ruby\n# Include the helper method\ninclude Mongoid::Denormalization\n\n# Define your denormalization\ndenormalize_from(:user, :name) # this will add a user_name field on your model\ndenormalize_from(:user, :email) # this will add a user_email field on your model\n```\n\nOptionally, you can also write it as\n```ruby\n# this will add a username field on your model\ndenormalize_from(:user, :name, :denormalized_field_name =\u003e :username)\n\n# this will add a useremail field on your model\ndenormalize_from(:user, :email, :denormalized_field_name =\u003e :useremail)\n```\n\nLets say we have a company model with embedded jobs in it. We want to denormalize user_name and user_email in jobs.\nWe can write the following code in our jobs model:\n\n```ruby\ndenormalize_from(:user, :name, to_klass_infos: [{\n  klasses: [::Company],\n  selector_proc: Proc.new do |id, value|\n    {:jobs =\u003e {\"$elemMatch\" =\u003e {:user_id =\u003e id, :user_name =\u003e {\"$ne\" =\u003e value}}}}\n  end,\n  updator: \"jobs.$.user_name\",\n  index_key: \"jobs.user_id\"\n}])\n\ndenormalize_from(:user, :email, to_klass_infos: [{\n  klasses: [::Company],\n  selector_proc: Proc.new do |id, value|\n    {:jobs =\u003e {\"$elemMatch\" =\u003e {:user_id =\u003e id, :user_email =\u003e {\"$ne\" =\u003e value}}}}\n  end,\n  updator: \"jobs.$.user_email\",\n  index_key: \"jobs.user_id\"\n}])\n```\n\nYou can call force_denormalize also,\n```ruby\ncompany.force_denormalize # this will simply sync all the denormalized fields and will not triiger a save on document.\ncompany.force_denormalize! # this will sync all the denormalized fields and will also triiger a save on document.\n```\n\nNote: you should also create proper db indexes required, otherwise the module may through an error.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/chaudhary/mongoid-denormalization. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\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## Code of Conduct\n\nEveryone interacting in the Mongoid::Denormalization project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/mongoid-denormalization/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchaudhary%2Fmongoid-denormalization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchaudhary%2Fmongoid-denormalization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchaudhary%2Fmongoid-denormalization/lists"}