title: How to write searchable method for belongs_to assocication using sunspot_rails gem
body: <p>I have two models. one is brand and another is product_detail. brands table has id and name fields and product_details table has fields id, name,price,discount and brand_id.</p>
  
  <p>brand has many product_details and product_detail belongs to brand</p>
  
  <p>brand.rb looks like:</p>
  
  <pre><code>class Brand &lt; ActiveRecord::Base
      has_many :product_details
  end
  </code></pre>
  
  <p>and product_details.rb looks like</p>
  
  <pre><code>class ProductDetail &lt; ActiveRecord::Base
      belongs_to :Brand, :dependent=&gt;:destroy
  end
  </code></pre>
  
  <p>Am trying to do searching using sunspot rails. I want to search based on brand name and product name with the user entered text. To do this I have written searchable method like this:</p>
  
  <pre><code>class ProductDetail &lt; ActiveRecord::Base
      belongs_to :brands, :dependent=&gt;:destroy
  
       searchable do
        text :name
        text :brands do
          brands.map(&amp;:name)
        end
      end
  end
  </code></pre>
  
  <p>When i run rake sunspot:reindex</p>
  
  <p>It is throwing an error undefined method map for nil class</p>
  
  <p>If change the code like this </p>
  
  <pre><code>class ProductDetail &lt; ActiveRecord::Base
      belongs_to :Brand, :dependent=&gt;:destroy
  
       searchable do
        text :name
        text :Brand do
          brands.map(&amp;:name)
        end
      end
  end
  </code></pre>
  
  <p>It is throwing an error undefined method brands for product_detail class</p>
  
  <p>Please help me how to do this.</p>