Ejemplo n.º 1
0
 /**
  * Method that retrieves one to many associated records
  * @param  \Cake\ORM\Table       $table       Table object
  * @param  \Cake\ORM\Association $association Association object
  * @return array                              associated records
  */
 protected function _oneToManyAssociatedRecords(\Cake\ORM\Table $table, \Cake\ORM\Association $association)
 {
     $assocName = $association->name();
     $assocTableName = $association->table();
     $assocForeignKey = $association->foreignKey();
     $recordId = $this->request->params['pass'][0];
     // get associated index View csv fields
     $fields = $this->_getTableFields($association);
     $query = $table->{$assocName}->find('all', ['conditions' => [$assocForeignKey => $recordId], 'fields' => $fields]);
     $records = $query->all();
     // store associated table records
     $result['records'] = $records;
     // store associated table fields
     $result['fields'] = $fields;
     // store associated table name
     $result['table_name'] = $assocTableName;
     return $result;
 }
 /**
  * Method that retrieves one to many associated records
  *
  * @param  \Cake\ORM\Association $association Association object
  * @param \Cake\Network\Request $request passed
  * @return array associated records
  */
 protected function _oneToManyAssociatedRecords(Association $association, Request $request)
 {
     $result = [];
     $assocName = $association->name();
     $assocTableName = $association->table();
     $assocForeignKey = $association->foreignKey();
     $recordId = $request->params['pass'][0];
     $csvFields = $this->_getAssociationCsvFields($association, static::ASSOC_FIELDS_ACTION);
     if (empty($csvFields)) {
         return $result;
     }
     // get associated index View csv fields
     $fields = array_unique(array_merge([$association->displayField()], $csvFields));
     $query = $this->_tableInstance->{$assocName}->find('all', ['conditions' => [$assocForeignKey => $recordId]]);
     $records = $query->all();
     // store association name
     $result['assoc_name'] = $assocName;
     // store associated table name
     $result['table_name'] = $assocTableName;
     // store associated table class name
     $result['class_name'] = $association->className();
     // store associated table display field
     $result['display_field'] = $association->displayField();
     // store associated table primary key
     $result['primary_key'] = $association->primaryKey();
     // store associated table foreign key
     $result['foreign_key'] = $association->foreignKey();
     // store associated table fields
     $result['fields'] = $fields;
     // store associated table records
     $result['records'] = $records;
     return $result;
 }