Answers.Body: <p>Finally discovered the solution to this, it was as Brad had suggested due to the query - however it was my incidental prepending of the plugin name to the table. ie. "gowander_trips" vs. "trips". After some digging and looking at other plugins it seems Craft does add the plugin name for you.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-03T19:25:43.163Z
Answers.LastActivityDate: 2015-05-03T19:25:43.163Z
Answers.UserDisplayName: Dale Inverarity
Body: <p>Trying to get an element setup but when index is loaded, I get a "Unknown Error has occurred", diving into logs I found a 500 error was being thrown from the <code>admin/actions/elementIndex/getElements</code> url.</p>
  
  <p>Full Element type code shown below.</p>
  
  <pre><code>&lt;?php
  namespace Craft;
  
  /**
   * GoWander - Trip element type
   */
  class GoWander_TripElementType extends BaseElementType
  {
      /**
       * Returns the element type name.
       *
       * @return string
       */
      public function getName()
      {
          return Craft::t('Trips');
      }
  
      /**
       * Returns whether this element type has content.
       *
       * @return bool
       */
      public function hasContent()
      {
          return true;
      }
  
      /**
       * Returns whether this element type has titles.
       *
       * @return bool
       */
      public function hasTitles()
      {
          return true;
      }
  
      /**
       * Returns this element type's sources.
       *
       * @param string|null $context
       * @return array|false
       */
      public function getSources($context = null)
      {
          $sources = array(
              '*' =&gt; array(
                  'label'    =&gt; Craft::t('All Trips'),
              )
          );
  
          foreach (craft()-&gt;goWander_template-&gt;findAll() as $template)
          {
              $key = 'template:'.$template-&gt;id;
  
              $sources[$key] = array(
                  'label'    =&gt; $template-&gt;name,
                  'criteria' =&gt; array('templateId' =&gt; $template-&gt;id)
              );
          }
  
          return $sources;
      }
  
      /**
       * Returns the attributes that can be shown/sorted by in table views.
       *
       * @param string|null $source
       * @return array
       */
      public function defineTableAttributes($source = null)
      {
          return array(
              'title'     =&gt; Craft::t('Title'),
          );
      }
  
      /**
       * Returns the table view HTML for a given attribute.
       *
       * @param BaseElementModel $element
       * @param string $attribute
       * @return string
       */
      public function getTableAttributeHtml(BaseElementModel $element, $attribute)
      {
          return parent::getTableAttributeHtml($element, $attribute);
      }
  
      /**
       * Defines any custom element criteria attributes for this element type.
       *
       * @return array
       */
      public function defineCriteriaAttributes()
      {
          return array(
              'price'   =&gt; AttributeType::Mixed,
          );
      }
  
      /**
       * Modifies an element query targeting elements of this type.
       *
       * @param DbCommand $query
       * @param ElementCriteriaModel $criteria
       * @return mixed
       */
      public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria)
      {
          $query
              -&gt;addSelect('gowander_trips.templateId')
              -&gt;join('gowander_trips trips', 'trips.id = elements.id');
  
          if ($criteria-&gt;price) {
  
              $query-&gt;andWhere(DbHelper::parseParam('gowander_trips.price', $criteria-&gt;price, $query-&gt;params));
          } 
  
      }
  
      /**
       * Populates an element model based on a query result.
       *
       * @param array $row
       * @return array
       */
      public function populateElementModel($row)
      {
          return GoWander_TripModel::populateModel($row);
      }
  
      /**
       * Returns the HTML for an editor HUD for the given element.
       *
       * @param BaseElementModel $element
       * @return string
       */
      public function getEditorHtml(BaseElementModel $element)
      {
          // Start/End Dates
          $html = craft()-&gt;templates-&gt;render('events/_edit', array(
              'element' =&gt; $element,
          ));
  
          // Everything else
          $html .= parent::getEditorHtml($element);
  
          return $html;
      }
  }
  </code></pre>
  
  <p>error:</p>
  
  <pre><code>CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'gowander_trips.templateId' in 'field list'. The SQL statement executed was: SELECT `elements`.`id`, `elements`.`type`, `elements`.`enabled`, `elements`.`archived`, `elements`.`dateCreated`, `elements`.`dateUpdated`, `elements_i18n`.`slug`, `elements_i18n`.`uri`, `elements_i18n`.`enabled` AS `localeEnabled`, `content`.`id` AS `contentId`, `content`.`title`, `content`.`field_body`, `gowander_trips`.`templateId`
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-30T13:55:21.607Z
Comments.Text: The underlying error message for the 500 Internal Server Error will be logged in your `craft\storage\runtime\logs` folder.  Can you check there and share what the error is?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-30T14:04:25.943Z
Comments.Text: Updated with db error.
Comments.UserDisplayName: Dale Inverarity
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-30T14:24:45.687Z
Comments.Text: It's probably choking on `->addSelect('gowander_trips.templateId')`. I'd check wherever you set that relationship up.
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-05-01T06:20:16.030Z
Comments.Text: Relationship follows same format as events example plugin, and it exists in table. Really stuck on what this could be. Code works if I change db queries over to events example so it must be something db related.
Comments.UserDisplayName: Dale Inverarity
Tags: <plugin-development><elementtype>
Title: 500 error on admin/actions/elementIndex/getElements
ThreadText: # 500 error on admin/actions/elementIndex/getElements
  
  (Asked by: username_0 on 2015-04-30)
  
  Trying to get an element setup but when index is loaded, I get a "Unknown Error has occurred", diving into logs I found a 500 error was being thrown from the `admin/actions/elementIndex/getElements` url.
  
  Full Element type code shown below.
  
  ```
  <?php
  namespace Craft;
  
  /**
   * GoWander - Trip element type
   */
  class GoWander_TripElementType extends BaseElementType
  {
      /**
       * Returns the element type name.
       *
       * @return string
       */
      public function getName()
      {
          return Craft::t('Trips');
      }
  
      /**
       * Returns whether this element type has content.
       *
       * @return bool
       */
      public function hasContent()
      {
          return true;
      }
  
      /**
       * Returns whether this element type has titles.
       *
       * @return bool
       */
      public function hasTitles()
      {
          return true;
      }
  
      /**
       * Returns this element type's sources.
       *
       * @param string|null $context
       * @return array|false
       */
      public function getSources($context = null)
      {
          $sources = array(
              '*' => array(
                  'label'    => Craft::t('All Trips'),
              )
          );
  
          foreach (craft()->goWander_template->findAll() as $template)
          {
              $key = 'template:'.$template->id;
  
              $sources[$key] = array(
                  'label'    => $template->name,
                  'criteria' => array('templateId' => $template->id)
              );
          }
  
          return $sources;
      }
  
      /**
       * Returns the attributes that can be shown/sorted by in table views.
       *
       * @param string|null $source
       * @return array
       */
      public function defineTableAttributes($source = null)
      {
          return array(
              'title'     => Craft::t('Title'),
          );
      }
  
      /**
       * Returns the table view HTML for a given attribute.
       *
       * @param BaseElementModel $element
       * @param string $attribute
       * @return string
       */
      public function getTableAttributeHtml(BaseElementModel $element, $attribute)
      {
          return parent::getTableAttributeHtml($element, $attribute);
      }
  
      /**
       * Defines any custom element criteria attributes for this element type.
       *
       * @return array
       */
      public function defineCriteriaAttributes()
      {
          return array(
              'price'   => AttributeType::Mixed,
          );
      }
  
      /**
       * Modifies an element query targeting elements of this type.
       *
       * @param DbCommand $query
       * @param ElementCriteriaModel $criteria
       * @return mixed
       */
      public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria)
      {
          $query
              ->addSelect('gowander_trips.templateId')
              ->join('gowander_trips trips', 'trips.id = elements.id');
  
          if ($criteria->price) {
  
              $query->andWhere(DbHelper::parseParam('gowander_trips.price', $criteria->price, $query->params));
          } 
  
      }
  
      /**
       * Populates an element model based on a query result.
       *
       * @param array $row
       * @return array
       */
      public function populateElementModel($row)
      {
          return GoWander_TripModel::populateModel($row);
      }
  
      /**
       * Returns the HTML for an editor HUD for the given element.
       *
       * @param BaseElementModel $element
       * @return string
       */
      public function getEditorHtml(BaseElementModel $element)
      {
          // Start/End Dates
          $html = craft()->templates->render('events/_edit', array(
              'element' => $element,
          ));
  
          // Everything else
          $html .= parent::getEditorHtml($element);
  
          return $html;
      }
  }
  
  ```
  
  error:
  
  ```
  CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'gowander_trips.templateId' in 'field list'. The SQL statement executed was: SELECT `elements`.`id`, `elements`.`type`, `elements`.`enabled`, `elements`.`archived`, `elements`.`dateCreated`, `elements`.`dateUpdated`, `elements_i18n`.`slug`, `elements_i18n`.`uri`, `elements_i18n`.`enabled` AS `localeEnabled`, `content`.`id` AS `contentId`, `content`.`title`, `content`.`field_body`, `gowander_trips`.`templateId`
  
  ```
  
  **Tags:** plugin-development, elementtype
  
  > **Comments:**
  > **username_1**: The underlying error message for the 500 Internal Server Error will be logged in your `craft\storage\runtime\logs` folder.  Can you check there and share what the error is?  
  > **username_0**: Updated with db error.  
  > **username_1**: It's probably choking on `->addSelect('gowander_trips.templateId')`. I'd check wherever you set that relationship up.  
  > **username_0**: Relationship follows same format as events example plugin, and it exists in table. Really stuck on what this could be. Code works if I change db queries over to events example so it must be something db related.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-05-03. Score: 0 | Accepted answer
  
  Finally discovered the solution to this, it was as username_1 had suggested due to the query - however it was my incidental prepending of the plugin name to the table. ie. "gowander\_trips" vs. "trips". After some digging and looking at other plugins it seems Craft does add the plugin name for you.
  
  
  ---
  
  