0
將應用程序轉換爲Rails 3.進入這個缺少的語法糖。Rails 3,has_many:through和<<運算符
class Group < ActiveRecord::Base
has_many :memberships
has_many :users, :through => :memberships
end
class Membership < ActiveRecord::Base
belongs_to :group
belongs_to :user
end
class User < ActiveRecord::Base
has_many :memberships
has_many :groups, :through => :memberships
end
我不能再這樣做對Rails 3:
$ group = Group.first
$ user = User.first
$ group.users << user
ActiveRecord::StatementInvalid: Mysql2::Error: Column 'user_id' cannot
be null: INSERT INTO `memberships` (`admin`, `created_at`,
`group_id`, `leader`, `updated_at`, `user_id`) VALUES
(0, '2010-11-03 18:31:33', 5, 0, '2010-11-03 18:31:33', NULL)
哪兒去<<
?它被替換了什麼?