I have a class named Post
:
class Post < ActiveRecord::Base
end
I have a class named Question
that inheriting from Post
:
class Question < Post
end
and I have a class named Answer
that also inheriting from 'Post':
class Answer < Post
end
In Post
, I have a column named post_type_id
and its' type is Integer
.
How do I use STI and specific column name & type to inherit from Post? 0
means Question
and 1
means Answer
. (0 & 1 is the value of post_type_id
in posts table)
There actually is a way, as with all things. You can override the find_sti_class method to look for your type based on an integer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With