0

I have one model User and will be creating another one Category.

Both will have a HABTM relationship between both.

I have not created the Category model yet.

But, when I am generating it at the command line, can I also generate the join table?

If so, how?

Thanks.

2 Answers 2

0

If you want to explicitly generate the junction table, use has_many :categories, through: :junction and has_many :users, through: :junction in your models. Then explicitly generate a model Junction that contains a user_id and category_id, and that belongs_to user and belongs_to category. The user and category will also need to have has_many :junctions.

1
  • I think you misunderstood what I am asking. What I want to know is if there is a rails command that I can run that will generate the other model - along with my join_table. Jun 13, 2012 at 4:30
0

As far as I can find, there is no way to generate the join table for a HABTM association at the command-line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.