Cake\ORM\Table::schema PHP Method

schema() public method

If an \Cake\Database\Schema\Table is passed, it will be used for this table instead of the default one. If an array is passed, a new \Cake\Database\Schema\Table will be constructed out of it and used as the schema for this table.
public schema ( array | Cake\Database\Schema\Table | null $schema = null ) : Cake\Database\Schema\Table
$schema array | Cake\Database\Schema\Table | null New schema to be used for this table
return Cake\Database\Schema\Table
    public function schema($schema = null)
    {
        if ($schema === null) {
            if ($this->_schema === null) {
                $this->_schema = $this->_initializeSchema($this->connection()->schemaCollection()->describe($this->table()));
            }
            return $this->_schema;
        }
        if (is_array($schema)) {
            $constraints = [];
            if (isset($schema['_constraints'])) {
                $constraints = $schema['_constraints'];
                unset($schema['_constraints']);
            }
            $schema = new Schema($this->table(), $schema);
            foreach ($constraints as $name => $value) {
                $schema->addConstraint($name, $value);
            }
        }
        return $this->_schema = $schema;
    }

Usage Example

 public function testDeteccaoAutomatica()
 {
     $this->Noticias->addBehavior("CakePtbr.AjusteData");
     $noticia = $this->__preparaNoticia();
     $this->assertEquals("datetime", $this->Noticias->schema()->columnType("publicado_em"));
     $this->assertEquals("2015-03-22", $noticia->get("autorizado_em"));
     $this->assertEquals("2015-03-25 16:42:05", $noticia->get("publicado_em"));
 }
All Usage Examples Of Cake\ORM\Table::schema