Acessando relacionamento no Datagrid Olá Pessoal, tudo bom? Como vocês fazem para acessar um valor vindo de um relacionamento para colocar em uma row no datagrid? $column_id_fornecedor = new TDataGridColumn('Pessoa::find(id_fornecedor)->nome_razao', 'Fornecedor', 'right'); Agradeço a tenção de todos!...
AR
Acessando relacionamento no Datagrid  
Olá Pessoal, tudo bom?

Como vocês fazem para acessar um valor vindo de um relacionamento para colocar em uma row no datagrid?

$column_id_fornecedor = new TDataGridColumn('Pessoa::find(id_fornecedor)->nome_razao', 'Fornecedor', 'right');


Agradeço a tenção de todos!

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (2)


AR

Minha solução!
$column_id_fornecedor->setTransformer( function($value, $object, $row) { $pessoa = new Pessoa($object->id_fornecedor); $despesa = new Despesa(); $despesa->pessoa = $pessoa; $value = $despesa->pessoa->nome_razao; return $value; });
MG

Angelo, faça o relacionamento no model, assim você acessaria:

$column_nome = new TDataGridColumn('pedido->nome','Noe Cliente','left');


Exemplo

 
  1. <?php
 
  1. <?php
  2. /**
  3. * ClienteContato Active Record
  4. * @author Marcelo Gomes
  5. */
  6. class ClienteContato extends TRecord
  7. {
  8. const TABLENAME = 'cliente_contato';
  9. const PRIMARYKEY= 'id';
  10. const IDPOLICY = 'serial'; // {max, serial}
  11. const CREATEDAT = 'created_at';
  12. const UPDATEDAT = 'updated_at';
  13. private $cliente;
  14. private $system_user;
  15. /**
  16. * Constructor method
  17. */
  18. public function __construct($id = NULL, $callObjectLoad = TRUE)
  19. {
  20. parent::__construct($id, $callObjectLoad);
  21. parent::addAttribute('cliente_id');
  22. parent::addAttribute('nome');
  23. parent::addAttribute('email');
  24. parent::addAttribute('telefone');
  25. parent::addAttribute('celular');
  26. parent::addAttribute('dia_mes');
  27. parent::addAttribute('departamento');
  28. parent::addAttribute('system_user_id');
  29. parent::addAttribute('created_at');
  30. parent::addAttribute('updated_at');
  31. }
  32. /**
  33. * Method set_cliente
  34. * Sample of usage: $cliente_contato->cliente = $object;
  35. * @param $object Instance of Cliente
  36. */
  37. public function set_cliente(Cliente $object)
  38. {
  39. $this->cliente = $object;
  40. $this->cliente_id = $object->id;
  41. }
  42. /**
  43. * Method get_cliente
  44. * Sample of usage: $cliente_contato->cliente->attribute;
  45. * @returns Cliente instance
  46. */
  47. public function get_cliente()
  48. {
  49. // loads the associated object
  50. if (empty($this->cliente))
  51. $this->cliente = new Cliente($this->cliente_id);
  52. // returns the associated object
  53. return $this->cliente;
  54. }
  55. /**
  56. * Method set_system_user
  57. * Sample of usage: $cliente_contato->system_user = $object;
  58. * @param $object Instance of SystemUser
  59. */
  60. public function set_system_user(SystemUser $object)
  61. {
  62. $this->system_user = $object;
  63. $this->system_user_id = $object->id;
  64. }
  65. /**
  66. * Method get_system_user
  67. * Sample of usage: $cliente_contato->system_user->attribute;
  68. * @returns SystemUser instance
  69. */
  70. public function get_system_user()
  71. {
  72. // loads the associated object
  73. if (empty($this->system_user))
  74. $this->system_user = new SystemUser($this->system_user_id);
  75. // returns the associated object
  76. return $this->system_user;
  77. }
  78. public function onBeforeStore($object)
  79. {
  80. $object->system_user_id = TSession::getValue('userid');
  81. }
  82. }
  83. ?>