-
-
Save anonymous/36f6b41353aceaacbb7b01a653418ab0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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