How to create a super class based on ActiveRecord::Base? For example: class ParentRecord < ActiveRecord::Base end class ChildRecord < ParentRecord end Rails always asks for ''parent_records'' table. Which has absolutely no need to exist at all. It''s intentionally made as a super class to be inherited. Thanks. -- Posted via http://www.ruby-forum.com/.
On 7/13/06, iseng <isengoi@gmail.com> wrote:> > How to create a super class based on ActiveRecord::Base? > > For example: > > class ParentRecord < ActiveRecord::Base > end > > class ChildRecord < ParentRecord > end > > Rails always asks for ''parent_records'' table. Which has absolutely no > need to exist at all. It''s intentionally made as a super class to be > inherited. > > Thanks.By doing this rails assumes you want to use single table inheritance. To do this you have a parent_records table with a type (string) field. There is a fair bit of information regarding STI kicking around especially on the wiki --> Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060713/8e68610d/attachment.html
Daniel ----- wrote:> By doing this rails assumes you want to use single table inheritance. > To do > this you have a parent_records table with a type (string) field. > > There is a fair bit of information regarding STI kicking around > especially > on the wiki > > --Hi Daniel thanks for the reply. The thing is, I don''t want to use Single Table Inheritance. I have several record objects based on TextRecord (which incorporates all text formatting functions). ActiveRecord::Base > TextRecord TextRecord > ForumPost TextRecord > Article TextRecord > PrivateMessage etc I want separate tables for each and everyone: forum_posts, articles, private_messages, etc. -- Posted via http://www.ruby-forum.com/.
On 7/13/06, iseng <isengoi@gmail.com> wrote:> Hi Daniel thanks for the reply. > > The thing is, I don''t want to use Single Table Inheritance. I have > several record objects based on TextRecord (which incorporates all text > formatting functions). > > ActiveRecord::Base > TextRecord > TextRecord > ForumPost > TextRecord > Article > TextRecord > PrivateMessage > etcclass TextRecord < ActiveRecord::Base self.abstract_class = true end class ForumPost < TextRecord end etc... Tom
On 7/13/06, iseng <isengoi@gmail.com> wrote:> > Daniel ----- wrote: > > By doing this rails assumes you want to use single table inheritance. > > To do > > this you have a parent_records table with a type (string) field. > > > > There is a fair bit of information regarding STI kicking around > > especially > > on the wiki > > > > -- > > Hi Daniel thanks for the reply. > > The thing is, I don''t want to use Single Table Inheritance. I have > several record objects based on TextRecord (which incorporates all text > formatting functions). > > ActiveRecord::Base > TextRecord > TextRecord > ForumPost > TextRecord > Article > TextRecord > PrivateMessage > etc > > I want separate tables for each and everyone: forum_posts, articles, > private_messages, etc.In this case, you would be best to put the common methods into a module and then include this module in the classes eg module MyModule def my_method do_something end end Put this into the lib directory of your app structure and put the include statement into your classes class PrivateMessage < ActiveRecord::Base include MyModule ... end etc This will provide the methods as instance methods on your classes. --> Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060713/8cdb0e22/attachment.html
On 7/13/06, Daniel N <has.sox@gmail.com> wrote:> > > > On 7/13/06, iseng <isengoi@gmail.com> wrote: > > > Daniel ----- wrote: > > > By doing this rails assumes you want to use single table inheritance. > > > To do > > > this you have a parent_records table with a type (string) field. > > > > > > There is a fair bit of information regarding STI kicking around > > > especially > > > on the wiki > > > > > > -- > > > > Hi Daniel thanks for the reply. > > > > The thing is, I don''t want to use Single Table Inheritance. I have > > several record objects based on TextRecord (which incorporates all text > > formatting functions). > > > > ActiveRecord::Base > TextRecord > > TextRecord > ForumPost > > TextRecord > Article > > TextRecord > PrivateMessage > > etc > > > > I want separate tables for each and everyone: forum_posts, articles, > > private_messages, etc. > > > In this case, you would be best to put the common methods into a module > and then include this module in the classes > > eg > module MyModule > def my_method > do_something > end > end > > Put this into the lib directory of your app structure and put the include > statement into your classes > class PrivateMessage < ActiveRecord::Base > include MyModule > ... > end > etc > > This will provide the methods as instance methods on your classes. >Or do what Tom suggests ;) Thanx Tom. I missed that one --> > > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060713/50f1c055/attachment.html