Model Without Associated Table

I have a tag cloud that is made up of Tags(model with table). I want
the tag cloud to be a model but I do not need a table since I am going
to get the data from Tag. I was wondering how do I create a model
that does not depend on a table? Is this a bad practice? Does anyone
see me doing it another way? Thanks :slight_smile:

–
John K.
[email protected]

Not every model (or ruby class ) needs to relate to a table in the
database. Actually a given class only gets that functionality when it
inherits from ActiveRecord::Base.

class TagCloud
…
end

would work without any related table…

hope that helps.

-Sean

Who would of thought. For some odd reason I was under the impression
that if I took out ActiveRecord::Base then the framework would burn
into the ground… but it still works :-).

On 9/9/06, [email protected] [email protected] wrote:

hope that helps.

-Sean

–
John K.
[email protected]

On Sep 8, 2006, at 8:53 PM, John K. wrote:

I have a tag cloud that is made up of Tags(model with table). I want
the tag cloud to be a model but I do not need a table since I am going
to get the data from Tag. I was wondering how do I create a model
that does not depend on a table? Is this a bad practice? Does anyone
see me doing it another way? Thanks :slight_smile:

–
John K.
[email protected]

In this case you may want to just make a plain old ruby class that

doesn’t inherit from AR::Base, put it in your models dir and let it
do whatever it wants to with the Tag model.

class TagCloud
def self.
Tag.find(:all, :limit => num) # or whatever, you get the idea.
end
end

You would use this to output a cloud of 25 tags like so:

TagCloud[25]

Or you can use some form of delegation to the Tag model. I use plain

ruby models like this as sort of coordination-models that coordinate
multiple ActiveRecord models but don’t need to keep their own state
in the database. So these are good places for complex logic that
deals with multiple AR models at once.

-Ezra