From 14dcefaa97f93e07f44b260e1083c69f0f1c356f 2012-08-21 17:15:59 From: Toshi MARUYAMA Date: 2012-08-21 17:15:59 Subject: [PATCH] set default category_id instead of the object (#11665) Rails 2.3 still has issues with synchronizing the association_id and association attributes of an object. That means, if you set the association with an object first and then just set the id afterwards, the object wins and the setting of the id gets lost. This is not an issue in Rails >= 3.1 anymore. Contributed by Holger Just. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.4-stable@10226 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/document.rb b/app/models/document.rb index d4a89ff..764dea7 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -42,7 +42,9 @@ class Document < ActiveRecord::Base def initialize(attributes=nil, *args) super if new_record? - self.category ||= DocumentCategory.default + # Rails3 use this instead + # self.category ||= DocumentCategory.default + self.category_id = DocumentCategory.default.id if self.category_id == 0 end end