Hi!
I'm designing CMS for a corporate use with Rails and I have a problem with
implementing some of my ideas about content structure.
In my plans, I want to have a model called Folder, to which all the relevant
data will be linked. Any folder can be a parent for any other Folder, so they
should create a hierarchical structure like this:
+ Folder 1
`- Folder 2
`- Folder 3
`- Folder 4
`- Folder 5
+ Folder 6
`- Folder 7
.....and so on
And now the problem: how can I do this with ActiveRecord?
I want to follow KISS for now, so `folders` table is like:
+ id
+ parent_id
+ name
+ description
However, I fear that there's no way to do 'has_many :folders' inside Folder
model, because it's not in AR's design(probably there'll be "name-guessing"
issues or someth like that). Any ideas are very, very appreciated!
Thanks in advance,
···
--
sdmitry -=- Dmitry V. Sabanin
MuraveyLabs.
Spam Here -> postmaster@sco.com
Dmitry V. Sabanin wrote:
I want to follow KISS for now, so `folders` table is like:
+ id
+ parent_id
+ name
+ description
However, I fear that there's no way to do 'has_many :folders' inside Folder model, because it's not in AR's design(probably there'll be "name-guessing" issues or someth like that). Any ideas are very, very appreciated!
This is no problem with ActiveRecord:
belongs_to :parent, :class_name => 'Folder', :foreign_key => 'folder_id'
has_many :children, :class_name => 'Folder', :foreign_key => 'folder_id'
···
--
http://www.mikrocontroller.net - Das Mikrocontroller-Forum
Super, but I'm not sure how to use that now. How can I add Folders to a
Folder? I've tried folder.folders << another_folder and folder.childrens <<
another_folder but with no success. Btw, big thanks for your help and quick
reply!
···
On Thursday 07 October 2004 18:44, Andreas Schwarz wrote:
This is no problem with ActiveRecord:
belongs_to :parent, :class_name => 'Folder', :foreign_key => 'folder_id'
has_many :children, :class_name => 'Folder', :foreign_key => 'folder_id'
--
sdmitry -=- Dmitry V. Sabanin
MuraveyLabs.
Spam Here -> postmaster@sco.com
Answering my own question with Andreas help from #rubyonrails, you have to use
Folder#children<< to add folder.
···
On Thursday 07 October 2004 19:09, Dmitry V. Sabanin wrote:
On Thursday 07 October 2004 18:44, Andreas Schwarz wrote:
> This is no problem with ActiveRecord:
>
> belongs_to :parent, :class_name => 'Folder', :foreign_key => 'folder_id'
> has_many :children, :class_name => 'Folder', :foreign_key => 'folder_id'
Super, but I'm not sure how to use that now. How can I add Folders to a
Folder? I've tried folder.folders << another_folder and folder.childrens <<
another_folder but with no success.
--
sdmitry -=- Dmitry V. Sabanin
MuraveyLabs.
Spam Here -> postmaster@sco.com