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?