Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4232670
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:07:26+00:00 2026-05-21T02:07:26+00:00

I’ve come across this rather odd bit of behaviour in a rails application I’m

  • 0

I’ve come across this rather odd bit of behaviour in a rails application I’m working on.

I have multiple types of Post in an inheritance heirarchy, and a Post has_many FeedEntries.

class Post < ActiveRecord::Base
    has_many :feed_entries
end

class Post::BlogPost < Post; end
class Post::Discussion < Post; end
class Post::Article < Post; end

class FeedEntry < ActiveRecord::Base
    belongs_to :post
end

Now, when I have everything set up as before, calling FeedEntry#post on a saved object always returns an object of the correct (subclass) type, as I would expect. However, if I make Post abstract (which it really should be – the superclass should never be instantiated in this model):

class Post < ActiveRecord::Base
    has_many :feed_entries
    self.abstract_class = true
end

_(note: I edited this code snippet to take into account tomafro’s suggestion below, as setting self.abstract_class seems more idiomatic than overriding self.abstract_class?. However, the same behaviour still persists.)

…then calling the FeedEntry#post association on a previously saved object returns an object of type Post. This seems rather backwards (given that the abstract class declaration denotes specifically that that class should not be instantiated), and I can’t think of a reason for this behaviour.

So, is there some reason for this I’m not getting, or is it a bug, or something else?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T02:07:27+00:00Added an answer on May 21, 2026 at 2:07 am

    By specifying self.abstract_class = true in the base object, you are essentially disabling STI. Setting self.abstract_class = true actually tells ActiveRecord that there is not a database table associated with that class so your inherited classes will each have their own database table.

    It sounds like what you want to do is remove self.abstract_class = true and simulate an abstract class by using the initialize method to only permit instantiation if the class is not of type Post.

    For example:

    class Post < ActiveRecord::Base    
      def initialize 
        raise "Post cannot be instantiated directly" if self.class == Post   
      end
    end
    

    This way, you maintain your STI model and also have a pseudo-abstract base class. Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.