Example #1
0
 /** Get all attributes from model name
  * @param string $model
  */
 public static function get_from_model($model)
 {
     $model::check_model();
     $result = array();
     $attrs = $model::get_attr_def();
     $relations = \Helper\Database\Relation::get_from_model($model);
     $id_col = $model::get_id_col($model);
     $result[$id_col] = self::from_def($id_col, array("type" => 'int', "is_unsigned" => true, "is_primary" => true, "is_autoincrement" => true));
     foreach ($attrs as $name => $def) {
         if (!$model::is_rel($name)) {
             $result[$name] = self::from_def($name, $def);
         }
     }
     foreach (self::$default_cols as $name => $def) {
         $result[$name] = self::from_def($name, $def);
     }
     return $result;
 }
Example #2
0
 private static function sync_bilinear_relation_table(\Helper\Database\Relation $rel)
 {
     $name = $rel->get_bilinear_table_name();
     $db = self::get_database();
     $table = $db->get_table($name);
     $mp = $rel->parent;
     $mm = $rel->model;
     $name_a = $mp::get_id_col();
     $name_b = $mm::get_id_col();
     $attrs = array(\Helper\Database\Attr::from_def('id_' . $name, array("type" => 'int', "is_unsigned" => true, "is_autoincrement" => true, "is_primary" => true)), \Helper\Database\Attr::from_def($name_a, array("type" => 'int', "is_unsigned" => true)), \Helper\Database\Attr::from_def($name_b, array("type" => 'int', "is_unsigned" => true)), \Helper\Database\Attr::from_def("created_at", array("type" => 'datetime', "default" => 'NOW()')), \Helper\Database\Attr::from_def("updated_at", array("type" => 'datetime', "default" => 'NOW()')));
     foreach ($attrs as $attr) {
         if (!$table->has_column($attr->name)) {
             $table->add_attr($attr);
         }
         $table->get_column($attr->name)->set_cfg($attr->get_data());
     }
     return $table->save();
 }