From 78c4e30c6df04be7148b36916455792b727cd55b Mon Sep 17 00:00:00 2001 From: Rob Looby Date: Fri, 1 May 2015 13:57:05 -0500 Subject: add upgrade note for breaking habtm change in 3.2 -> 4.0 The has_and_belongs_to_many default join_table behavior changed between Rails 3.2 and Rails 4.0 and should be noted in the appropriate section of the upgrade guide. commit: https://github.com/rails/rails/commit/46492949b8c09f99db78b9f7a02d039e7bc6a702 --- guides/source/upgrading_ruby_on_rails.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index 0aa2152d56..be7d2a3635 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -883,6 +883,18 @@ this gem such as `whitelist_attributes` or `mass_assignment_sanitizer` options. * To re-enable the old finders, you can use the [activerecord-deprecated_finders gem](https://github.com/rails/activerecord-deprecated_finders). +* Rails 4.0 has changed to default join table for `has_and_belongs_to_many` relations to strip the common prefix off the second table name. Any existing `has_and_belongs_to_many` relationship between models with a common prefix must be specified with the `join_table` option. For example: + +```ruby +CatalogCategory < ActiveRecord::Base + has_and_belongs_to_many :catalog_products, join_table: 'catalog_categories_catalog_products' +end + +CatalogProduct < ActiveRecord::Base + has_and_belongs_to_many :catalog_categories, join_table: 'catalog_categories_catalog_products' +end +``` + ### Active Resource Rails 4.0 extracted Active Resource to its own gem. If you still need the feature you can add the [Active Resource gem](https://github.com/rails/activeresource) in your Gemfile. -- cgit v1.2.3 From 2ffeee3d2a211f7bb84c6b209c6d2c576ae6d586 Mon Sep 17 00:00:00 2001 From: Rob Looby Date: Sun, 3 May 2015 11:52:45 -0500 Subject: add note about habtm relations with scopes --- guides/source/upgrading_ruby_on_rails.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md index be7d2a3635..49834fa8a2 100644 --- a/guides/source/upgrading_ruby_on_rails.md +++ b/guides/source/upgrading_ruby_on_rails.md @@ -895,6 +895,8 @@ CatalogProduct < ActiveRecord::Base end ``` +* Note that the the prefix takes scopes into account as well, so relations between `Catalog::Category` and `Catalog::Product` or `Catalog::Category` and `CatalogProduct` need to be updated similarly. + ### Active Resource Rails 4.0 extracted Active Resource to its own gem. If you still need the feature you can add the [Active Resource gem](https://github.com/rails/activeresource) in your Gemfile. -- cgit v1.2.3