[Opda-develop] OPDA/app/models category.rb,1.2,1.3
Brought to you by:
digitalpodcast
|
From: Alex N. <dig...@us...> - 2006-07-17 05:18:37
|
Update of /cvsroot/opda/OPDA/app/models In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv13412/app/models Modified Files: category.rb Log Message: changed category model to acts as nested set Index: category.rb =================================================================== RCS file: /cvsroot/opda/OPDA/app/models/category.rb,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** category.rb 28 Jun 2006 22:02:42 -0000 1.2 --- category.rb 17 Jul 2006 05:18:35 -0000 1.3 *************** *** 2,5 **** has_and_belongs_to_many :channels has_and_belongs_to_many :items ! acts_as_tree :order => 'title' end --- 2,27 ---- has_and_belongs_to_many :channels has_and_belongs_to_many :items ! acts_as_nested_set :scope => :root ! ! def before_create ! # Update the child object with its parents attrs ! unless self[:parent_id].to_i.zero? ! self[:depth] = parent[:depth].to_i + 1 ! self[:root_id] = parent[:root_id].to_i ! end ! end ! ! def after_create ! # Update the parent root_id with its id ! if self[:parent_id].to_i.zero? ! self[:root_id] = self[:id] ! self.save ! else ! parent.add_child self ! end ! end ! ! def parent ! @parent ||= self.class.find(self[:parent_id]) ! end end |