{"id":17775472,"url":"https://github.com/pikachuexe/active_record_tweaks","last_synced_at":"2025-08-31T13:30:33.681Z","repository":{"id":11604673,"uuid":"14097767","full_name":"PikachuEXE/active_record_tweaks","owner":"PikachuEXE","description":"Active Record is great, but could be better. Here are some tweaks for it.","archived":false,"fork":false,"pushed_at":"2024-12-26T00:24:34.000Z","size":98,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-04T10:32:11.319Z","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/PikachuEXE.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["PikachuEXE"]}},"created_at":"2013-11-04T01:39:29.000Z","updated_at":"2024-12-26T00:24:37.000Z","dependencies_parsed_at":"2024-08-13T02:39:47.140Z","dependency_job_id":"c8273188-8758-4dbd-8fe3-6103a7a988e0","html_url":"https://github.com/PikachuEXE/active_record_tweaks","commit_stats":{"total_commits":93,"total_committers":3,"mean_commits":31.0,"dds":"0.043010752688172005","last_synced_commit":"6bc0a007919481a59463e9711dffdb06084185c0"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/PikachuEXE/active_record_tweaks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PikachuEXE%2Factive_record_tweaks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PikachuEXE%2Factive_record_tweaks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PikachuEXE%2Factive_record_tweaks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PikachuEXE%2Factive_record_tweaks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PikachuEXE","download_url":"https://codeload.github.com/PikachuEXE/active_record_tweaks/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PikachuEXE%2Factive_record_tweaks/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272988237,"owners_count":25026955,"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","status":"online","status_checked_at":"2025-08-31T02:00:09.071Z","response_time":79,"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-10-26T21:57:37.083Z","updated_at":"2025-08-31T13:30:33.446Z","avatar_url":"https://github.com/PikachuEXE.png","language":"Ruby","funding_links":["https://github.com/sponsors/PikachuEXE"],"categories":[],"sub_categories":[],"readme":"# Active Record Tweaks\n\nActive Record is great, but could be better. Here are some tweaks for it.\n\n\n## Status\n\n[![GitHub Build Status](https://img.shields.io/github/actions/workflow/status/PikachuEXE/active_record_tweaks/tests.yaml?branch=master\u0026style=flat-square)](https://github.com/PikachuEXE/active_record_tweaks/actions/workflows/tests.yaml)\n\n[![Gem Version](http://img.shields.io/gem/v/active_record_tweaks.svg?style=flat-square)](http://badge.fury.io/rb/active_record_tweaks)\n[![License](https://img.shields.io/github/license/PikachuEXE/active_record_tweaks.svg?style=flat-square)](http://badge.fury.io/rb/active_record_tweaks)\n\n[![Coverage Status](http://img.shields.io/coveralls/PikachuEXE/active_record_tweaks.svg?style=flat-square)](https://coveralls.io/r/PikachuEXE/active_record_tweaks)\n[![Code Climate](https://img.shields.io/codeclimate/maintainability/PikachuEXE/active_record_tweaks.svg?style=flat-square)](https://codeclimate.com/github/PikachuEXE/active_record_tweaks)\n\n\u003e The above badges are generated by https://shields.io/\n\n\n## Installation\n\n```ruby\ngem 'active_record_tweaks'\n```\n\n\n## Usage\n\nEither include it in specific record or just `ActiveRecord::Base`\n```ruby\nclass SomeRecord\n  include ActiveRecordTweaks::Integration::InstanceMethods\n  # This module is also DEPRECATED\n  # See below for details\n  extend  ActiveRecordTweaks::Integration::ClassMethods\n\n  # DEPRECATED\n  include ActiveRecordTweaks\nend \n\n# or\n\n# In a initialzer\n# DEPRECATED\nActiveRecord::Base.send(:include, ActiveRecordTweaks)\n```\n\n\n### `#cache_key_without_timestamp`\nNothing special, just like `record.cache_key`  \nBut it has no timestamp so you can use it for scoped cache key  \ne.g. When caching with Cookie, which you want to control the expiry time independent of record update time  \nUsage:\n```ruby\n  # Just like using #cache_key\n  record.cache_key_without_timestamp\n```\n\n\n### `#cache_key_from_attributes`\nNothing special, just like `record.cache_key` in rails 4.1  \nBut it does not check against columns  \ne.g. When you have some virtual timestamp attribute method (cached or not)  \nJust make sure you throw some name to it or it will raise error  \nAlias: `#cache_key_from_attribute`  \nUsage:\n```ruby\n  # Just like using #cache_key\n  record.cache_key_from_attributes(:happy_at, :children_max_updated_at)\n```\n\n\n### `.cache_key`\n\n**DEPRECATED**  \nThis method does NOT consider the query like filters and and sort orders.  \nThus deprecated without replacement.  \nRails 5 already have `#cache_key` in relation class: https://github.com/rails/rails/pull/20884  \nThere is also a gem for older rails: https://github.com/customink/activerecord-collection_cache_key  \n\n**Usage**  \nThere is no class level cache key for ActiveRecord at the moment (4.0.1)  \nPassing an array to `cache_digest` could lead to performance issue and the key can become too long when collection is big  \n([rails#12726](https://github.com/rails/rails/pull/12726))  \nThis is used for getting a cache key for a ActiveRecord class for all record (I don't know how to write one for `Relation`, could be similar)  \nYou can use it for class level caching (like displaying all Categories or a random list of 5 users  \nAnd the cache would only expire when there is any record created, updated, or deleted (since `count` and maximum of `updated_at` are used)  \n```ruby\nPerson.count # =\u003e 1000\nPerson.maximum(:updated_at) # =\u003e 20131106012125528738000\nPerson.cache_key # =\u003e \"people/all/1000-20131106012125528738000\"\n\n# When record has multiple updated columns\nPerson.maximum(:updated_at) # =\u003e 20131106012125528738000\nPerson.maximum(:updated_on) # =\u003e 20141106012125528738000\nPerson.cache_key(:update_at, :updated_on)     # =\u003e \"people/all/1000-20141106012125528738000\" (not empty but has mutiple updated timestamp columns)\n\n# Just get cache key without timestamp\nPerson.maximum(:updated_on) # =\u003e some timestamp\nPerson.cache_key(nil)     # =\u003e \"people/all/1000\"\n\n# Other examples\nProduct.cache_key     # =\u003e \"products/all/0\" (empty, has updated timestamp columns or not)\nProduct.cache_key     # =\u003e \"products/all/1\" (not empty but has no updated timestamp columns)\n```\nUsage:\n```ruby\nRecordClass.cache_key\n```\nYou can also use it with multiple records (Rails 4 Record might have `updated_at` and `updated_on`)\n```ruby\nRecordClass.cache_key(:updated_at, :updated_on)\n```\n\n\n### `.cache_key_without_timestamp`\n\n**DEPRECATED**  \nSame deprecation reasons and replacement suggestion as `.cache_key` above  \n\n**Usage**\nJust like `.cache_key(nil)`  \nBut much clearer\n```ruby\nPerson.count # =\u003e 1000\nPerson.maximum(:updated_at) # =\u003e 20131106012125528738000\nPerson.cache_key_without_timestamp # =\u003e \"people/all/1000\"\n\n# Other examples\nProduct.cache_key_without_timestamp     # =\u003e \"products/all/0\" (empty, has updated timestamp columns or not)\nProduct.cache_key_without_timestamp     # =\u003e \"products/all/1\" (not empty but has no updated timestamp columns)\n```\nUsage:\n```ruby\nRecordClass.cache_key_without_timestamp\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpikachuexe%2Factive_record_tweaks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpikachuexe%2Factive_record_tweaks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpikachuexe%2Factive_record_tweaks/lists"}