{"id":20502510,"url":"https://github.com/hamuyuuki/activerecord-creating_foreign_keys","last_synced_at":"2025-04-13T20:14:17.657Z","repository":{"id":62552845,"uuid":"308993039","full_name":"hamuyuuki/activerecord-creating_foreign_keys","owner":"hamuyuuki","description":"Define FOREIGN KEY Constraints in a CREATE TABLE Statement","archived":false,"fork":false,"pushed_at":"2020-11-13T01:07:17.000Z","size":67,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T20:14:10.776Z","etag":null,"topics":["foreign-keys","gem","mysql","rails","ruby"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/activerecord-creating_foreign_keys","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/hamuyuuki.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-31T23:57:22.000Z","updated_at":"2021-07-16T01:21:02.000Z","dependencies_parsed_at":"2022-11-03T04:15:29.174Z","dependency_job_id":null,"html_url":"https://github.com/hamuyuuki/activerecord-creating_foreign_keys","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hamuyuuki%2Factiverecord-creating_foreign_keys","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hamuyuuki%2Factiverecord-creating_foreign_keys/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hamuyuuki%2Factiverecord-creating_foreign_keys/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hamuyuuki%2Factiverecord-creating_foreign_keys/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hamuyuuki","download_url":"https://codeload.github.com/hamuyuuki/activerecord-creating_foreign_keys/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248774969,"owners_count":21159534,"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":["foreign-keys","gem","mysql","rails","ruby"],"created_at":"2024-11-15T19:23:20.761Z","updated_at":"2025-04-13T20:14:17.602Z","avatar_url":"https://github.com/hamuyuuki.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Gem Version](https://badge.fury.io/rb/activerecord-creating_foreign_keys.svg)](https://badge.fury.io/rb/activerecord-creating_foreign_keys)\n[![Build Status](https://travis-ci.com/hamuyuuki/activerecord-creating_foreign_keys.svg?branch=master)](https://travis-ci.com/hamuyuuki/activerecord-creating_foreign_keys)\n[![Maintainability](https://api.codeclimate.com/v1/badges/3cac3284bb083ea1f9cd/maintainability)](https://codeclimate.com/github/hamuyuuki/activerecord-creating_foreign_keys/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/3cac3284bb083ea1f9cd/test_coverage)](https://codeclimate.com/github/hamuyuuki/activerecord-creating_foreign_keys/test_coverage)\n\n# activerecord-creating_foreign_keys\n`activerecord-creating_foreign_keys` defines FOREIGN KEY Constraints in a CREATE TABLE Statement.\n\nRails 4.2 [supports adding and removing foreign keys](https://guides.rubyonrails.org/v4.2/4_2_release_notes.html#foreign-key-support). And Rails 4.2.1 [supports adding a `:foreign_key` option to `references`](https://github.com/rails/rails/blob/4-2-stable/activerecord/CHANGELOG.md#rails-421-march-19-2015).\nBut it defines FOREIGN KEY Constraints in a ALTER TABLE Statement as an additional DDL when you define a `:foreign_key` option to `references`.\n\nRails 5 [supports defining FOREIGN KEY Constraints in a CREATE TABLE Statement](https://github.com/rails/rails/pull/20009/files). So `activerecord-creating_foreign_keys` backports that into Rails 4.2.\n\n## Getting Started\nInstall `activerecord-creating_foreign_keys` at the command prompt:\n```sh\ngem install activerecord-creating_foreign_keys\n```\n\nOr add `activerecord-creating_foreign_keys` to your Gemfile:\n```ruby\ngem \"activerecord-creating_foreign_keys\"\n```\n\n## How to use\nYou don't need to do anything after installing `activerecord-creating_foreign_keys`.\n\nYou can know **Before** and **After** if `articles` is created.\n\n```\ncreate_table :articles do |t|\n  t.references :author, foreign_key: true\nend\n```\n\n**Before**\n```sql\nCREATE TABLE `articles` (`id` int(11) auto_increment PRIMARY KEY, `author_id` int(11));\nALTER TABLE `articles` ADD CONSTRAINT `fk_rails_e74ce85cbc` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`);\n```\n\n**After**\n```sql\nCREATE TABLE `articles` (`id` int(11) auto_increment PRIMARY KEY, `author_id` int(11), CONSTRAINT `fk_rails_e74ce85cbc` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`));\n```\n\n## Limitation\nAt this time, only the `mysql2` adapter support this function.\n\n## Contributing\nBug reports and pull requests are welcome on GitHub at https://github.com/hamuyuuki/activerecord-creating_foreign_keys. 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`activerecord-creating_foreign_keys` is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhamuyuuki%2Factiverecord-creating_foreign_keys","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhamuyuuki%2Factiverecord-creating_foreign_keys","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhamuyuuki%2Factiverecord-creating_foreign_keys/lists"}