Say I want to gather info from various Models… Files, Folders, and put
them into a ‘display’ Object DisplayFilesystem that will standarize the
info from both tables (for display only)…
Class DisplayFilesystem
attr_accessor :item_id, :name, :type, :description, :date
def initialize
@item_id = @name = @type = @description = @date = nil
end
end
So in the code side I will get the info and put it into an array of
objects and send it to the template.
However, these are my Models (assume the DB tables are good):
class Fileset < ActiveRecord::Base
belongs_to :folder
belongs_to :datafile
end
class Folder < ActiveRecord::Base
#acts_as_tree :order => “name”,
:counter_cache => true
has_many :filesets
has_many :datafiles,
:through => :filesets
belongs_to :parent,
:counter_cache => true,
:class_name => “Folder”
has_many :children,
:class_name => “Folder”,
:foreign_key => “parent_id”,
:order => “name”,
:dependent => true
end
class Datafile < ActiveRecord::Base
has_many :filesets
has_many :folders,
:through => :filesets
end
So my questions are:
1). Is there a better way to do this? If not, WHERE do these custom
classes go?
2). As you can see, I’m using the acts_as_tree (exploded) on my Folder
model… I can get all it’s Folder children fine… but I have to get
it’s Datafile children separately. Is there a way to get them all in one
object and then that way sending that into the template instead of my
DisplayFilesystem hack?
Sorry but I figured I needed to be verbose. :-/
thanks,
ro