CD
Datagrid não aparece descrição - relacionamento de associação
Pessoal tenho duas tabelas simples.
localidade:
cidade:
PHP: Cidade.php:
localidade:
CREATE TABLE IF NOT EXISTS `intranet`.`localidade` (
`idlocalidade` INT NOT NULL,
`localidade` VARCHAR(45) NULL,
`idcidade` INT NOT NULL,
PRIMARY KEY (`idlocalidade`),
INDEX `fk_localidade_cidade_idx` (`idcidade` ASC),
CONSTRAINT `fk_localidade_cidade`
FOREIGN KEY (`idcidade`)
REFERENCES `intranet`.`cidade` (`idcidade`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
cidade:
CREATE TABLE IF NOT EXISTS `intranet`.`cidade` (
`idcidade` INT NOT NULL,
`descricao` VARCHAR(255) NULL,
PRIMARY KEY (`idcidade`))
ENGINE = InnoDB
PHP: Cidade.php:
<?phpclass Cidade extends TRecord{ const TABLENAME = 'cidade'; const PRIMARYKEY= 'idcidade'; const IDPOLICY = 'max'; // {max, serial} public function __construct($id = NULL, $callObjectLoad = TRUE) { parent::__construct($id, $callObjectLoad); parent::addAttribute('descricao'); }}?>
PHP: Localidade.php:
<?phpclass Localidade extends TRecord{ const TABLENAME = 'localidade'; const PRIMARYKEY= 'idlocalidade'; const IDPOLICY = 'max'; // {max, serial} private $cidade; public function __construct($id = NULL, $callObjectLoad = TRUE) { parent::__construct($id, $callObjectLoad); parent::addAttribute('localidade'); parent::addAttribute('idcidade'); } public function set_cidade(Cidade $object) { $this->cidade = $object; $this->cidade_id = $object->id; } public function get_cidade() { // loads the associated object if (empty($this->cidade)) $this->cidade = new Cidade($this->cidade_id); // returns the associated object return $this->cidade; }}?>
Parte do código LocalidadeFormList.php:
<?php // creates a Datagrid $this->datagrid = new BootstrapDatagridWrapper(new TDataGrid); $this->datagrid->style = 'width: 100%'; // $this->datagrid->datatable = 'true'; // $this->datagrid->enablePopover('Popover', 'Hi <b> {name} </b>'); // creates the datagrid columns $column_idlocalidade = new TDataGridColumn('idlocalidade', 'ID', 'left'); $column_localidade = new TDataGridColumn('localidade', 'Localidade', 'left'); //$column_idcidade = new TDataGridColumn('idcidade', 'ID Cidade', 'left'); $column_cidade = new TDataGridColumn('cidade->descricao', 'Cidade', 'left'); // add the columns to the DataGrid $this->datagrid->addColumn($column_idlocalidade); $this->datagrid->addColumn($column_localidade); //$this->datagrid->addColumn($column_idcidade); $this->datagrid->addColumn($column_cidade);?>
Mas não está aparecendo a "descricao" no datagrid e não aparece erro nenhum na tela, nem de php nem do framework.
Conseguem perceber qual o erro?
Framework 8.0.
Aparentemente falta as chaves do if nessa parte:
public function get_cidade()
{
// loads the associated object
if (empty($this->cidade))
$this->cidade = new Cidade($this->cidade_id);
// returns the associated object
return $this->cidade;
}
Não está apresentando nenhum erro no log do PHP ?
Descobri o problema.
É que na minha tabela o primary key é idcidade.
Mas o gerador de entidade do Studio Pro gerou assim:
Agora está funcionando. Mas engraçado que não gerava erro, apenas não apresentava a descrição quando eu chamava
na coluna do grid.