Skip to content

Instantly share code, notes, and snippets.

@cpierce
Created June 3, 2016 05:24
Show Gist options
  • Save cpierce/a896873a26c49ff240bc02292a84315f to your computer and use it in GitHub Desktop.
Save cpierce/a896873a26c49ff240bc02292a84315f to your computer and use it in GitHub Desktop.
$data['feeds']['_ids'] = $this->request->data['feeds'];
$calendars = TableRegistry::get('Calendars');
$calendar = $calendars->get($this->request->data['id'], [
'associated' => [
'Feeds',
],
]);
$calendar = $calendars->patchEntity($calendar, $data);
if ($calendars->save($calendar, ['associated' => ['Feeds']])) {
echo 'yes';
} else {
echo 'no';
}
debug($calendar);
die();
===DEBUG===
no
/src/Controller/Api/FeedsController.php (line 37)
object(App\Model\Entity\Calendar) {
'id' => (int) 1,
'title' => 'TEST 1',
'calendar_event_count' => (int) 0,
'is_visible' => true,
'api_key_id' => (int) 1,
'color' => null,
'created' => null,
'modified' => object(Cake\I18n\FrozenTime) {
'time' => '2016-06-02T21:50:29+00:00',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'feeds' => [
(int) 0 => object(App\Model\Entity\Calendar) {
'id' => (int) 37,
'title' => 'TEST 2',
'calendar_event_count' => null,
'is_visible' => true,
'api_key_id' => (int) 1,
'color' => null,
'created' => null,
'modified' => null,
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Feeds'
},
(int) 1 => object(App\Model\Entity\Calendar) {
'id' => (int) 127,
'title' => 'TEST 3',
'calendar_event_count' => null,
'is_visible' => true,
'api_key_id' => (int) 1,
'color' => null,
'created' => null,
'modified' => null,
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Feeds'
}
],
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [
'feeds' => true
],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [
'title' => [
'_required' => 'A title is required.'
]
],
'[invalid]' => [],
'[repository]' => 'Calendars'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment