Code Monkey home page Code Monkey logo

activerecord-creating_foreign_keys's Introduction

Gem Version Build Status Maintainability Test Coverage

activerecord-creating_foreign_keys

activerecord-creating_foreign_keys defines FOREIGN KEY Constraints in a CREATE TABLE Statement.

Rails 4.2 supports adding and removing foreign keys. And Rails 4.2.1 supports adding a :foreign_key option to references. But it defines FOREIGN KEY Constraints in a ALTER TABLE Statement as an additional DDL when you define a :foreign_key option to references.

Rails 5 supports defining FOREIGN KEY Constraints in a CREATE TABLE Statement. So activerecord-creating_foreign_keys backports that into Rails 4.2.

Getting Started

Install activerecord-creating_foreign_keys at the command prompt:

gem install activerecord-creating_foreign_keys

Or add activerecord-creating_foreign_keys to your Gemfile:

gem "activerecord-creating_foreign_keys"

How to use

You don't need to do anything after installing activerecord-creating_foreign_keys.

You can know Before and After if articles is created.

create_table :articles do |t|
  t.references :author, foreign_key: true
end

Before

CREATE TABLE `articles` (`id` int(11) auto_increment PRIMARY KEY, `author_id` int(11));
ALTER TABLE `articles` ADD CONSTRAINT `fk_rails_e74ce85cbc` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`);

After

CREATE TABLE `articles` (`id` int(11) auto_increment PRIMARY KEY, `author_id` int(11), CONSTRAINT `fk_rails_e74ce85cbc` FOREIGN KEY (`author_id`) REFERENCES `authors` (`id`));

Limitation

At this time, only the mysql2 adapter support this function.

Contributing

Bug 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 code of conduct.

License

activerecord-creating_foreign_keys is available as open source under the terms of the MIT License.

activerecord-creating_foreign_keys's People

Contributors

hamuyuuki avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.