title: using mongoid on sinatra , model inheritance causing "uninitialized constant" modelname (parent class)
body: <p>I'm using Mongoid on Sinatra . And I use</p>
  
  <pre><code>Dir.glob(File.join(File.dirname(__FILE__),'models','*.rb')).each do |file|
    require file
  end
  </code></pre>
  
  <p>to load mongoid model files.</p>
  
  <p>I tried to add a model B inherit from A ,like:</p>
  
  <p>models/a.rb:</p>
  
  <pre><code>class A
    include Mongoid::Document
    include Mongoid::Timestamps
    field :custom_id, type: Integer
  end
  </code></pre>
  
  <p>models/b.rb</p>
  
  <pre><code>class B &lt; A
    field :title , type: String
    field :body , type: String
  end
  </code></pre>
  
  <p>But when I exec the App , I got errors :</p>
  
  <pre><code>uninitialized constant A (NameError)
  </code></pre>
  
  <p>So I'm trying to find a solution for this, 
  it could be fixed by add:</p>
  
  <pre><code>require A
  </code></pre>
  
  <p>at the top of model B , But I think  it may not be a good way to solve it. </p>
  
  <p>So , is there anyother way to fix this?? </p>
  
  <hr>
  
  <p>Regards</p>