Model are like:
class Forrest < ActiveRecord::Base
has_many :trees, inverse_of: :forrest
has_many :oak_trees, inverse_of: :forrest
has_many :palm_trees, inverse_of: :forrest
end
class Tree < ActiveRecord::Base
belongs_to :forrest, inverse_of: :trees
end
class OakTree < Tree
def height=(value)
# Stuff
end
end
Then this:
forrest = Forrest.create
forrest.oak_trees.build(height: :tall)
In the height=
method I need forrest
, but it's nil. I assume there must be some way to correct this.
I tried moving the belongs_to
from Tree
to the subclasses and adding like inverse_of: oak_trees
.
But I cannot figure out how to make it work.