1

I have two models that share some of the same attributes so I wanted to setup a single table inheritance structure. After doing some research, I found out that I can use module to achieve the same by doing the following instead:

module CommonFields
  def self.included base
    base.class_eval do
      include DataMapper::Resource

        property :type, base::Discriminator
        property :enable_feature1, base::Boolean, :default => false
        property :enable_feature2, base::Boolean, :default => false
    end
  end
end

class A
  include CommonFields

    property: title, String
end

class B
  include CommonFields
end

However, when I do rake db:automigrate I get:

undefined method `properties' for CommonFields:Module /usr/local/rvm/gems/ruby-1.9.2-p290/gems/dm-core-1.2.0/lib/dm-core/associations/relationship.rb:252:in `parent_key'

Any ideas?

Thanks,

Paul

pwc
  • 161
  • 1
  • 10

1 Answers1

0

I think I know what the problem is. What I didn't realize was that I had an association in class B that was referencing CommonFields. This is what's causing this problem! Need to rethink how I am going to do this.

pwc
  • 161
  • 1
  • 10