{"id":19211617,"url":"https://github.com/marcusg/foreign_key_validation","last_synced_at":"2026-06-16T03:32:12.908Z","repository":{"id":20184720,"uuid":"23455758","full_name":"marcusg/foreign_key_validation","owner":"marcusg","description":"Protect the foreign keys in your Rails models","archived":false,"fork":false,"pushed_at":"2015-06-21T18:34:49.000Z","size":508,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-14T03:04:46.537Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marcusg.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}},"created_at":"2014-08-29T07:09:35.000Z","updated_at":"2014-09-02T06:35:39.000Z","dependencies_parsed_at":"2022-07-21T07:33:18.398Z","dependency_job_id":null,"html_url":"https://github.com/marcusg/foreign_key_validation","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/marcusg/foreign_key_validation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcusg%2Fforeign_key_validation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcusg%2Fforeign_key_validation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcusg%2Fforeign_key_validation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcusg%2Fforeign_key_validation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcusg","download_url":"https://codeload.github.com/marcusg/foreign_key_validation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcusg%2Fforeign_key_validation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34390052,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-16T02:00:06.860Z","response_time":126,"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-11-09T13:43:07.425Z","updated_at":"2026-06-16T03:32:12.891Z","avatar_url":"https://github.com/marcusg.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# foreign_key_validation\n\n[![Coverage Status](https://coveralls.io/repos/marcusg/foreign_key_validation/badge.png?branch=master)](https://coveralls.io/r/marcusg/foreign_key_validation?branch=master)\n[![Code Climate](https://codeclimate.com/github/marcusg/foreign_key_validation/badges/gpa.svg)](https://codeclimate.com/github/marcusg/foreign_key_validation)\n[![Build Status](https://travis-ci.org/marcusg/foreign_key_validation.svg?branch=master)](https://travis-ci.org/marcusg/foreign_key_validation)\n[![Gem Version](https://badge.fury.io/rb/foreign_key_validation.svg)](http://badge.fury.io/rb/foreign_key_validation)\n\nProtect your models by specifying a collection of relations that should be tested for consistency with a predefined column (e.g. `user_id`).This is useful when the column `user_id` is used in multiple models. We can check if the `user_id` of *model A* matches `user_id` of *model B* before saving the records - if the IDs are different, an error will be attached to the errors hash of checked model.\n\n## Requirements\n\n    ruby \u003e= 1.9.3\n    active_record \u0026 active_support \u003e= 3.2.0\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'foreign_key_validation'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install foreign_key_validation\n\n## Usage\n\nCall `validate_foreign_keys` below the association definitions (`belongs_to`, ...) in your model. By default it assumes that it should check all `belongs_to` relations against the `user_id` column. So any relation will be checked for a matching `user_id`.\n\nChange behaviour by calling `validate_foreign_keys` with arguments hash.\n\n    validate_foreign_keys on: :admin_user, with: [:project]\n\nThis would only check `model.project.admin_user_id` to match `model.admin_user_id` before saving the record.\n\n## Configuration\n\nYou can customize the default behaviour of the gem by calling the `configure` method on the module with a block (e.g. initializer).\n\n    ForeignKeyValidation.configure do |config|\n      config.error_message      = lambda { |key, name, object| \"My custom msg!\" }\n      config.inject_subclasses  = false     # default: true\n      config.validate_against   = :admin    # default: :user\n    end\n\n## Tests\n\nUse these commands to run the testsuite against different versions of ActiveRecord\n\n    bundle\n    appraisal install\n    appraisal rspec\n\n## Contributing\n\n1. Fork it ( https://github.com/marcusg/foreign_key_validation/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcusg%2Fforeign_key_validation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcusg%2Fforeign_key_validation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcusg%2Fforeign_key_validation/lists"}