So this is more or less of what I'm trying:
I have an abstract class extracted out for all the common functionalities, Which includes a polymorphic association, so it looks like this:
class Card < ActiveRecord::Base
self.abstract_class = true
belongs_to :cardable, polymorphic: true
...
end
class Spell < Card
...
end
class Unit < Card
...
end
Now when i try to use polymorphic associations on this, something on the lines of:
class Deck < ActiveRecord::Base
has_many :cards, :as => :cardable
end
class Hand < ActiveRecord::Base
has_many :cards, :as => :cardable
end
The belongs_to
part of things work fine,
i.e. spell.cardable
works perfectly as expected
However, because of the abstract class, has_many
doesn't work well
i.e. hand.cards
or deck.cards
always gives an empty ActiveRecord Association
Is this a workable model, or if not, what would be a better way to model this entire scenario?