/**
  * Build query for load operation.
  *
  * @param   \JDatabaseQuery  $query  The query object to handle.
  *
  * @return  \JDatabaseQuery  Return handled query object.
  */
 public function buildLoadQuery(\JDatabaseQuery $query = null)
 {
     $conditions = array();
     foreach ($this->fks as $field => $foreign) {
         $conditions[$foreign] = $this->parent->{$field};
     }
     $query = $query ?: $this->db->getQuery(true);
     QueryHelper::buildWheres($query, $conditions);
     $query->select('*')->from($this->tableName);
     return $query;
 }
 /**
  * Batch update some data.
  *
  * @param string $table      Table name.
  * @param string $data       Data you want to update.
  * @param mixed  $conditions Where conditions, you can use array or Compare object.
  *                           Example:
  *                           - `array('id' => 5)` => id = 5
  *                           - `new GteCompare('id', 20)` => 'id >= 20'
  *                           - `new Compare('id', '%Flower%', 'LIKE')` => 'id LIKE "%Flower%"'
  *
  * @return  boolean True if update success.
  */
 public static function updateBatch($table, $data, $conditions = array())
 {
     $db = static::getInstance();
     $query = $db->getQuery(true);
     // Build conditions
     $query = QueryHelper::buildWheres($query, $conditions);
     // Build update values.
     $fields = array_keys(static::getColumns($table));
     $hasField = false;
     foreach ((array) $data as $field => $value) {
         if (!in_array($field, $fields)) {
             continue;
         }
         $query->set($query->format('%n = %q', $field, $value));
         $hasField = true;
     }
     if (!$hasField) {
         return false;
     }
     $query->update($table);
     return $db->setQuery($query)->execute();
 }