Skip to content

Provides generator for generating HABTM-migrations for Rails 4+

License

Notifications You must be signed in to change notification settings

krishnakumar03/ruby-habtm-generator

 
 

Repository files navigation

HabtmGenerator

Build Status

Installation

Add this line to your application's Gemfile:

gem 'habtm_generator', :group => :development

And then execute:

$ bundle

Usage

rails generate habtm user post

This will generate a migration, for:

  • creating table "posts_users" with user_id, post_id, no primary key
  • index on both columns

And will copy the "has_and_belongs_to_many :model" into both models (near the top of the models)

This process is reversible (with rails destroy habtm model1 model2).

Potential Caveats

  • Namespaced models should work (tested in form admin/post). This will generate more verbose habtm lines in the model, with explicit table names and key names
  • Default: adds unique-constraint on index. I find this most useful for most situations. Just remove that from the generated migration before rake db:migrate.

About

Provides generator for generating HABTM-migrations for Rails 4+

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 93.3%
  • HTML 6.7%