{"id":20061658,"url":"https://github.com/tylerrick/paper_trail-active_record","last_synced_at":"2025-10-17T17:41:05.613Z","repository":{"id":56887396,"uuid":"258324901","full_name":"TylerRick/paper_trail-active_record","owner":"TylerRick","description":"Various ActiveRecord extensions to make your life easier when working with PaperTrail versions","archived":false,"fork":false,"pushed_at":"2022-06-07T00:25:21.000Z","size":28,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-21T00:02:58.092Z","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/TylerRick.png","metadata":{"files":{"readme":"Readme.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":"License","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-23T20:39:12.000Z","updated_at":"2022-04-27T20:17:35.000Z","dependencies_parsed_at":"2022-08-20T15:20:56.526Z","dependency_job_id":null,"html_url":"https://github.com/TylerRick/paper_trail-active_record","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Fpaper_trail-active_record","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Fpaper_trail-active_record/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Fpaper_trail-active_record/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Fpaper_trail-active_record/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TylerRick","download_url":"https://codeload.github.com/TylerRick/paper_trail-active_record/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241488198,"owners_count":19970829,"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-13T13:21:21.797Z","updated_at":"2025-10-17T17:41:00.547Z","avatar_url":"https://github.com/TylerRick.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PaperTrail::ActiveRecordExt\n\n[![Gem Version][1]][2]\n[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](https://rdoc.info/github/TylerRick/paper_trail-active_record/master)\n\nVarious ActiveRecord extensions to make your life easier when working with\n[PaperTrail](https://github.com/paper-trail-gem/paper_trail) versions and versioned model records.\n\n## Methods added to models with `has_paper_trail`\n\n- `.versions`\n- `.find_deleted_version`\n- `.find_deleted`\n- `.has_many_versions`\n- `.has_related_versions`\n- `.has_versions_with_all_related`\n- `created_version`\n- `paper_trail_update_column_using_value_from_changes`\n- `paper_trail_update_columns_using_value_from_changes`\n\n## Methods added to `PaperTrail::Version` (`VersionConcern`)\n\n- `.preceding_inclusive`\n- `.between_inclusive`\n- `scope :where_object_changed`\n- `scope :where_object_changed_any`\n- `#action`\n- `#item_class`\n\n## `{association}_or_deleted`\n\n### `def define_assoc_or_deleted(assoc_name, suffix: nil)`\n\nDefines a `{association}_or_deleted` method for the given association. This method will call\nthe usual association method to try to find the associated record but if that returns nil,\nwill fall back to looking for a deleted record from the `versions` history (using\n`klass.find_deleted`).\n\nYou can replace the `or_deleted` part with a different suffix using `suffix:` option.\n\nYou can even give it the same name as the existing association method if you want to override\nthe existing method with one that always falls back to looking for a deleted record.\n\n```ruby\nclass Post\n  belongs_to :author\n  # overrides author method with a version that finds deleted if not found\n  define_assoc_or_deleted :author, suffix: nil\n```\n\n### Automatically add for all assocations\n\nIf you include `PaperTrail::ActiveRecordExt::OrDeleted` into a model, it will automatically add a `{association}_or_deleted`\nmethod for every `belongs_to` or `has_one` association that is defined.\n\nBecause it reflects on all associations on that model as soon as it is included, make sure to\ninclude it *after* all of your associations are defined. You can also call\n`define_assoc_or_deleted_on_all_associations` at the end of your model class (that is the same\nmethod that including the module triggers).\n\nIf you want it to automatically be added for all assocations on *all* application models, you can\nuse [gem 'active_record_include'](https://github.com/TylerRick/active_record_include) like this:\n\n```ruby\n  class ApplicationRecord \u003c ActiveRecord::Base\n    include_when_connected PaperTrail::ActiveRecordExt::OrDeleted\n```\n\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'paper_trail-active_record'\n```\n\nAnd then execute:\n\n    $ bundle\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\nhttps://github.com/TylerRick/paper_trail-active_record.\n\n[1]: https://badge.fury.io/rb/paper_trail-active_record.svg\n[2]: https://rubygems.org/gems/paper_trail-active_record\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftylerrick%2Fpaper_trail-active_record","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftylerrick%2Fpaper_trail-active_record","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftylerrick%2Fpaper_trail-active_record/lists"}