LazyRecord\Metadata::init PHP Method

init() public method

This method initialize the metadata table if needed.
public init ( )
    public function init()
    {
        $parser = TableParser::create($this->connection, $this->driver);
        $tables = $parser->getTables();
        // if the __meta__table is not found, we should create one to prevent error.
        // this will be needed for the compatibility of the older version lazyrecord.
        if (!in_array('__meta__', $tables)) {
            $schema = new \LazyRecord\Model\MetadataSchema();
            $builder = \LazyRecord\SqlBuilder\SqlBuilder::create($this->driver);
            $sqls = $builder->build($schema);
            foreach ($sqls as $sql) {
                $this->connection->query($sql);
            }
        }
    }

Usage Example

Beispiel #1
0
 public function testCollection()
 {
     $metadata = new Metadata($this->conn, $this->queryDriver);
     $metadata->init();
     $metadata['version'] = 1;
     $metadata['name'] = 'c9s';
     $metas = new LazyRecord\Model\MetadataCollection();
     foreach ($metas as $meta) {
         ok($meta);
     }
 }