Ok, so, I have an rss feed class derived from activerecord:
class Feed < ActiveRecord::Base
has_many :feed_items
#.... lots of stuff here for caching and the like .....
end
This all works great. But I also want to play with del.icio.us and
Flickr''s rss feeds. Ideally, I''d like to have classes like:
class FeedItem < ActiveRecord::Base
#.... blah blah ....
end
class FlickrFeedItem < FeedItem
def image
#.... blah blah ....
end
def thumbnail
#.... blah blah ....
end
def tags
#.... blah blah ....
end
end
class DeliciousFeedItem < FeedItem
def tags
#.... blah blah ....
end
end
Or some suchlike thing.
Is there any way I can make this class
class FlickrFeed < Feed
end
return feed_items of type FlickrFeedItem?
Am I stuck with:
class FlickrFeed < Feed
has_many :flickr_feed_items, :foreign_key => "feed_id"
end
?
--
Bob Aman
On Thu, 24 Mar 2005 17:29:50 -0800, D Andrew Reynhout <reynhout-Yp+tNMrX9ANBDgjK7y7TUQ@public.gmane.org> wrote:> It sounds like you need Class Table Inheritance. There''s a patch > (RESEARCH) by johnwilger-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org to implement CLSTI, which I am > using for a similar need. > > http://dev.rubyonrails.com/ticket/600 > > AndrewWell, no. See, the inherited classes need to be using the *exact same* table. The extra methods are using the same table field, they''re just doing some extra processing on top of what already exists. This works I think: class FlickrFeed < Feed has_many :feed_items, :class_name => "FlickrFeedItem", :foreign_key => "feed_id" end It looks like it overwrites the feed_items from the parent with the version I wanted. Is there anything really wrong with this approach? -- Bob Aman