TextPost、ImagePost、およびLinkPostサブクラス(STIを使用)を持つPostクラスがあります。これらのPostタイプは、Post.type
(STI規則に従って)の文字列として指定されます。
TextPost.all
、、と呼べますが、問題ImagePost.all
ありませんLinkPost.all
。
まだ電話できると思っていましPost.all
たが、次のエラーが発生します。
ActiveRecord::SubclassNotFound: The single-table inheritance mechanism failed to locate the subclass: 'text'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite Post.inheritance_column to use another column for that information.
参考までに、これが私のschema.rbの関連部分です。
create_table "posts", :force => true do |t|
t.string "title"
t.string "type"
t.integer "author_id"
t.datetime "publish_datetime"
...
end
そして私のサブクラス(それぞれが適切な名前の.rbファイルにあります):
class TextPost < Post
...
end
class ImagePost < Post
...
end
class LinkPost < Post
...
end
私は何か間違ったことをしていますか?または、STIを使用しているときに親クラスを(単純かつ簡潔に)呼び出すことはできませんか?