Skip to content

Instantly share code, notes, and snippets.

/inspection2.php Secret

Created May 25, 2017 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/36f6b41353aceaacbb7b01a653418ab0 to your computer and use it in GitHub Desktop.
Save anonymous/36f6b41353aceaacbb7b01a653418ab0 to your computer and use it in GitHub Desktop.
public function edit(int $id) {
$this->loadModel('results');
if ( $id ) {
$entity = $this->results->find()->where(['id' => $id]);
} else {
$entity = $this->results->newEntity();
}
$requestData = $this->request->getData();
$this->loadModel('results.Attachments');
$AttachmentsModel = $this->Attachments;
$attachments = array();
if ( $this->request->getData() ) {
// upload to third party
foreach ($this->request->getData('files') as $file) {
// code
$attachments[] = [
'file_id' => $file_id,
'id' => $id
];
}
$requestData['attachments'] = $attachments;
$patchedEntity = $this->results>patchEntity(
$entity,
$requestData,
// NOT USED APPARENTLY [ 'associated' => 'attachments' ]
);
$errors = $patchedEntity->errors();
if ( empty ( $errors ) ) {
if ( !$this->results->save($entity, [
/* NOT USED APPARENTLY
'associated' => [
'attachments'
]*/
]);
}
}
}
ResultsTable.php:
$this->hasMany('Attachments', [
'className' => 'Results.Attachments',
'foreignKey' => 'result_id'
]);
ResultsAttachments.php:
$this->belongsTo('Results', [
'className' => 'Results',
'foreignKey' => 'result_id'
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment