/** * Synchronize models state with database * * @param object Models * @return void */ public static final function syncdb(ORM $gas) { $table = $gas->validate_table()->table; $primary_key = $gas->primary_key; $foreign_key = $gas->foreign_key; // Check table existence if (self::driver('sqlite')) { return Core::$db->truncate($table); } elseif (Core::$db->table_exists($table)) { return Core::$db->truncate($table); } //Build the new one now foreach ($gas->meta->get('fields') as $field => $rule) { $annotation = $rule['annotations']; $fields[$field] = Core::identify_annotation($annotation); } // Add the field annotations self::forge()->add_field($fields); // Add primay key if exists if (!empty($primary_key)) { self::forge()->add_key($primary_key, TRUE); } // Add composite keys if exists if (!empty($foreign_key)) { foreach ($foreign_key as $key) { self::forge()->add_key($key, TRUE); } } // Create those table if necessary if (!Core::$db->table_exists($table)) { self::forge()->create_table($table); } }