gridatk4agiletoolkit

GRID COLUMNS atk4 agiletoolkit


Hi I am trying to get some referenced data from another table,

Data structure:

Table PartDetail
-id
-OperationTypeID(foreign key)
-DateAdded

Table OperationType
-id
-Description

I am trying something like this:

$crud = $this->add('MVCGrid', array('allow_edit'=>false));
$crud->setModel('Model_PartDetail',array('DateAdded'));

But then I want to see the "description" from table OperationType, because on my PartDetail model I declare my relationship like this:

$this->hasOne('OperationType','OperationTypeID','Description') ->mandatory(true)
->caption('Operation Type');

for example in this case I want to see the description from the table OperationType

I tried: $crud->setModel('Model_PartDetail',array('DateAdded','OperationType'));

but is not working, only works with: $crud->setModel('Model_PartDetail',array('DateAdded','OperationTypeID'));

but I get only the ID number, not the description.

How this works?


Solution

  • I was able to solved it.

    on the model you need to redefine it as

    $ref = $this->add('Field_Reference', 'OperationTypeID');
    $ref->dereferenced_field='OperationTypeDescription';
    
    $m = $this->add('Model_OperationType');
    $m->addField('D'); // <-- actually seems that this line is not working
    
    $ref->setModel($m, 'Description');
    

    And then in the page you can actually added as OperationTypeDescription:

    $crud->setModel('Model_PartDetail', array('DateAdded', 'OperationTypeDescription'));