> * * belongs_to :parent, :class_name => ''Media'',
:foreign_key =>
> ''parent_id''
> has_many :children, :class_name => ''Media'',
:foreign_key =>
> ''parent_id'', :dependent => true
> or this?
> acts_as_tree :order => ''name'', :class_name =>
''Media'', :foreign_key
> => ''position_id''
The latter is more correct. While the first example may work, the
second is more concise and makes use of the auto-generated
acts_as_tree methods, "parent" and "children". Normally,
it''s not
necessary to use the :class_name and :foreign_key fields in an
acts_as_tree definition, since it knows that you''re talking about the
model itself (the model in which you use the "acts_as_tree" method
call). As far as I know :class_name doesn''t do anything, and
:foreign_key is only necessary if the parent_id field is called
something other than parent_id.
I think you may be wanting to do this:
class Media < ActiveRecord::Base
acts_as_tree :order => ''position_id''
end
You will then be able to access Media objects in your controller (or
view) like this:
@my_media_object = Media.find(1)
for @medium in @my_media_object.children
# Do something with each @medium object
end
> How i insert position_id in model, I need to do it?
Use the :order => "position_id" parameter.
> Thank you..
You''re welcome. Have fun!
Duane Johnson
(canadaduane)