Example #1
0
 /**
  * Removes a version
  */
 public static function delete_version($version)
 {
     $table = NimbleRecord::$adapter->quote_table_name(static::migration_table_name());
     $query = new NimbleQuery(NimbleQuery::DELETE);
     $query->from = $table;
     $query->where = NimbleQuery::condition('version', $version);
     $sql = $query->build();
     Migration::execute($sql);
 }
Example #2
0
 /**
  * Checks weither a record exists or not
  * @param string $col Column name you wish to check
  * @param string $value Value you wish to check aginst
  * @todo add multi conditional support
  */
 public static function exists()
 {
     $args = func_get_args();
     $query = new NimbleQuery();
     $query->select = '1';
     $query->from = static::table_name();
     $query->limit = '0,1';
     if (count($args) == 2) {
         $col = $args[0];
         $value = $args[1];
         $query->where = NimbleQuery::condition(static::sanatize_input_array($col), static::sanatize_input_array($value));
     } elseif (is_array($args[0])) {
         $conditions = array();
         foreach ($args[0] as $col => $value) {
             $conditions[] = NimbleQuery::condition(static::sanatize_input_array($col), static::sanatize_input_array($value));
         }
         $query->where = implode(' AND ', $conditions);
     }
     $sql = $query->build();
     unset($query);
     $result = static::execute($sql);
     $return = $result->fetch_assoc();
     if (isset($return['1'])) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * Performs a find for has_many->as (polymorphic)
  * @param NimbleRecord $class
  * @param string $name - association name
  * @param array $options
  */
 protected static function has_many_polymorphic_find($class, $name, $options = array())
 {
     $id = $class->row[NimbleRecord::$primary_key_field];
     $model = static::model($name);
     $polymorphic_column_type = $options['as'] . '_type';
     $polymorphic_column_id = $options['as'] . '_id';
     $class = strtolower(static::class_as_string($class));
     $conditions = implode(' AND ', array(NimbleQuery::condition($polymorphic_column_type, $class), NimbleQuery::condition($polymorphic_column_id, $id)));
     if (strpos($id, 'IN') !== false) {
         $conditions = implode(' AND ', array(NimbleQuery::condition($polymorphic_column_type, $class), $polymorphic_column_id . $id));
     }
     $merg_conditions = array($conditions);
     if (!is_null($options['conditions'])) {
         $merg_conditions[] = $options['conditions'];
     }
     $options['conditions'] = implode(' AND ', $merg_conditions);
     return call_user_func("{$model}::find_all", $options);
 }