0.02
No commit activity in last 3 years
No release in over 3 years
Generates has-and-belongs-to-many migrations. Use rails generate habtm model1 model2
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

HabtmGenerator

Build Status Gem Version

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.