Log message #4227648

# At Username Text
# Feb 18th 2020, 18:47 ndm `all()` will return a result set, which implements the collection interface. Try `$data['recommendations']['_ids'] = $query->extract('id')->toArray();`.
# Feb 18th 2020, 18:44 ricksaccous Oh
# Feb 18th 2020, 18:43 FunkadelicRelic .
# Feb 18th 2020, 18:43 FunkadelicRelic to integer
# Feb 18th 2020, 18:43 FunkadelicRelic array
# Feb 18th 2020, 18:43 FunkadelicRelic If I just do $query, I then get Cannot convert value of type
# Feb 18th 2020, 18:39 FunkadelicRelic Sorry, I don't really understand. I don't recall deliberately writing to session anywhere. If I do $data['recommendations']['_ids'] = [1, 2]; then it saves perfectly so I guess it's something in the block of code I pasted above?
# Feb 18th 2020, 18:38 ricksaccous check it in debug
# Feb 18th 2020, 18:38 ricksaccous if all ur selecting is id, I think...
# Feb 18th 2020, 18:37 ricksaccous also you wouldn't need to do $query['id'] you'd just do $query
# Feb 18th 2020, 18:37 ricksaccous where are you writing to session?
# Feb 18th 2020, 18:35 FunkadelicRelic Thanks @ricksaccous - if I swap that out I get the following error: Argument 1 passed to Cake\Http\Session::_overwrite() must be of the type array, null given, called in /var/www/html/csa-portal-3/vendor/cakephp/cakephp/src/Http/Session.php on line 491
# Feb 18th 2020, 18:33 ricksaccous do toArray();
# Feb 18th 2020, 18:33 ricksaccous instead of ->all();
# Feb 18th 2020, 18:33 ricksaccous by default a query returns a query object
# Feb 18th 2020, 18:29 FunkadelicRelic If I replace the last bit with a manual array of values instead of $query['id'] such as [1, 2] it works perfectly.
# Feb 18th 2020, 18:28 FunkadelicRelic When I do the debug, I'm getting the correct recommendations, it's just the last line I think I may be doing wrong.
# Feb 18th 2020, 18:28 FunkadelicRelic }
# Feb 18th 2020, 18:28 FunkadelicRelic $data['recommendations']['_ids'] = $query['id'];
# Feb 18th 2020, 18:28 FunkadelicRelic //debug($query);
# Feb 18th 2020, 18:28 FunkadelicRelic ->all();
# Feb 18th 2020, 18:28 FunkadelicRelic ->where([$data['recommendationgroup_id'] => 'recommendation_group_id'])
# Feb 18th 2020, 18:28 FunkadelicRelic ->select(['id'])
# Feb 18th 2020, 18:28 FunkadelicRelic ->disableHydration()
# Feb 18th 2020, 18:28 FunkadelicRelic $recommendations = TableRegistry::get('Recommendations');
# Feb 18th 2020, 18:28 FunkadelicRelic $query = $recommendations->find()
# Feb 18th 2020, 18:28 FunkadelicRelic {
# Feb 18th 2020, 18:28 FunkadelicRelic public function beforeMarshal(\Cake\Event\Event $event, \ArrayObject $data, \ArrayObject $options)
# Feb 18th 2020, 18:28 FunkadelicRelic I'm doing this:
# Feb 18th 2020, 18:28 FunkadelicRelic @ndm - Hey - sorry to bug you again, but I've been trying to implement your suggestion for earlier about the beforeMarshal and adding recommendations to my assessment. I'm getting there I think but I'm just getting caught up actually modifying the data.
# Feb 18th 2020, 15:57 birdy247 then the id was as expected
# Feb 18th 2020, 15:56 birdy247 I had to select '*', 'p.id'
# Feb 18th 2020, 15:32 neon1024 With auto-incrementing id’s is often easy to mistake id’s :)
# Feb 18th 2020, 15:32 neon1024 Perhaps the id you’re expecting is in row 2?
# Feb 18th 2020, 15:31 neon1024 I would also consider that because you’ve got `limit(1)` you might be getting more than one record back, and thus your expecting to see something and instead seeing something else
# Feb 18th 2020, 15:30 neon1024 You already are with `select *` right?
# Feb 18th 2020, 15:22 birdy247 Or would I have to select every field in the select clause
# Feb 18th 2020, 15:22 birdy247 Is there a way to ensure that the ID selected is that of purchases
# Feb 18th 2020, 15:21 birdy247 Where I check $legacyPurchase['id'] it is giving me the ID of the merchandise not the purchase
# Feb 18th 2020, 15:21 slackebot ->fetchAll('assoc');```
# Feb 18th 2020, 15:21 birdy247 ``` $legacyPurchases = $this->migrationConfig ->getLegacyConnection() ->newQuery() ->select(['*']) ->from(['p' => 'purchases']) ->innerJoin(['v' => 'variations'], ['v.id = p.variation_id']) ->innerJoin(['m' => 'merchandises'], ['m.id = v.merchandise_id']) ->where(['m.organiser_id' => $this->organiserId]) ->limit(1) ->execute()