/** * Return all of the rows in the result as an array. * * @param string column for associative keys * @param string column for values * @return array */ public function as_array($key = NULL, $value = NULL) { $model = Jelly::model_name($this->_model); foreach (array('key', 'value') as $var) { // Only alias meta-aliases if (${$var} && FALSE !== strpos(${$var}, ':')) { ${$var} = Jelly::meta_alias($model, ${$var}, NULL); } } return $this->_result->as_array($key, $value); }
/** * Returns the actual column name for a field, field alias, or meta-alias. * * $field must be in the format of "model.field". Supply $value if * you want the unique_key meta-alias to work properly. * * An array is returned containing the table and column keys. If the model's meta is found, * but the field can't be found, 'column' will contain the field name passed. * * Returns FALSE on failure. * * @param string $field * @return array */ public static function alias($field, $value = NULL) { if (FALSE !== strpos($field, '.')) { list($model, $field) = explode('.', $field); } else { $model = NULL; } // We should at least return something now $table = $model; $column = $field; // Hopefully we can find a meta object by now $meta = Jelly::meta($model); // Check for a meta-alias first if (FALSE !== strpos($field, ':')) { $field = $column = Jelly::meta_alias($meta, $field, $value); } if ($meta) { $table = $meta->table(); // Alias the field if ($field = $meta->fields($field)) { $column = $field->column; } } return array('table' => $table, 'column' => $column); }