Log message #4154171

# At Username Text
# Jun 27th 2018, 10:19 josbeir ah you just typed that nm :P
# Jun 27th 2018, 10:19 josbeir @turkles array_keys($collection->toArray()) ?
# Jun 27th 2018, 10:10 turkles well.. array_keys($collection->toArray()) works.. eww
# Jun 27th 2018, 10:09 neon1024 Well it implements Iterator, so perhaps you could just do `array_keys($collection)` ?
# Jun 27th 2018, 10:06 turkles extract wants a path.. but I can see you can do a callback.. hrm
# Jun 27th 2018, 10:05 turkles my collection does.. it's come from json data and is in the form 123 => ['data' => 'blah, 'etc' => 'blah], 456 =>...
# Jun 27th 2018, 10:02 neon1024 https://book.cakephp.org/3.0/en/core-libraries/collections.html#Cake\Collection\Collection::extract
# Jun 27th 2018, 10:02 neon1024 Probably `extract()` I’d think
# Jun 27th 2018, 10:01 neon1024 Do they even have keys?
# Jun 27th 2018, 09:56 turkles Is there a quick way to get a list of keys in a collection?
# Jun 27th 2018, 09:37 neon1024 Also do check the execution time without debug on
# Jun 27th 2018, 09:37 itamer My pleasure @gs13006, nice to be able to help and be helped
# Jun 27th 2018, 09:36 gs13006 @itamer thankyou very much
# Jun 27th 2018, 09:34 gs13006 Yes, i did it. may be i need to check this again.
# Jun 27th 2018, 09:34 itamer I run some massive queries, and they're fast - you will be able to fix this
# Jun 27th 2018, 09:33 itamer Once it's fast in the database, then you can look to see if there are any inefficiencies in your controller and models
# Jun 27th 2018, 09:33 itamer use debug tools to get the query and see if you can get it running faster in phpMyAdmin or whatever tool you are using.
# Jun 27th 2018, 09:32 itamer and look at the table type - is it optimised for the type of data you have
# Jun 27th 2018, 09:32 itamer look at your indexes in the database
# Jun 27th 2018, 09:32 itamer consider unbinding those tables if the data isn't needed
# Jun 27th 2018, 09:31 itamer Have a look at your recursive value - cut that down
# Jun 27th 2018, 09:31 gs13006 yes it is associated with each other.
# Jun 27th 2018, 09:31 itamer do you need those extra tables loaded every time?
# Jun 27th 2018, 09:31 gs13006 2x
# Jun 27th 2018, 09:30 itamer what version of cake @gs13006?
# Jun 27th 2018, 09:30 gs13006 @itamer I'm running a cakephp website, i have user table and the user table is related with more then 3 table. when i tried to open this it will always taking 20 sec. even i'm crated cache for this.
# Jun 27th 2018, 09:30 itamer thanks for your help @neon1024
# Jun 27th 2018, 09:25 itamer got it :slightly_smiling_face:
# Jun 27th 2018, 09:25 itamer ->Mtypes->name;
# Jun 27th 2018, 09:24 itamer What's the correct notation when it's a variable on a joined table?
# Jun 27th 2018, 09:24 itamer My ->name; command at the end will need to change, right?
# Jun 27th 2018, 09:20 itamer ok, I'm starting to work on that so I'll continue down that path. This part of the site requires very little work so I'm diving into v3 infrequently. I spend most of my time working with v2 where it's super-easy
# Jun 27th 2018, 09:20 neon1024 Which sidesteps the hasMany issue by inverting the association to a belongsTo making the query join easier :slightly_smiling_face:
# Jun 27th 2018, 09:19 neon1024 Ah ok, then I would just query `Finances` and contain `Mtypes`
# Jun 27th 2018, 09:19 itamer ok, thanks, I'll try that - I only need the Mtypes name field value for the most recent payment
# Jun 27th 2018, 09:19 neon1024 I guess a third, and little more obscure way, would be to use a subquery
# Jun 27th 2018, 09:18 neon1024 In which case, if you don’t want that, you’ll want to use `matching()` to filter the `Mtypes` by the associated `Finances`
# Jun 27th 2018, 09:18 neon1024 If you move the conditions into the contain, you can still return Mtypes though, but the associated Finances could be `null`
# Jun 27th 2018, 09:17 neon1024 @itamer I would suspect that `MTypes` hasMany `Finances`, so the contain would do a separate query, to get the multiples. So you will need to put your filtering of the `Finances` table into the contain using a closure, or use `matching()`
# Jun 27th 2018, 09:11 slackebot4 ->order(['Finances.enddate' => 'DESC']) ->first() ->name; it falls over with SELECT Mtypes.name AS `Mtypes__name` FROM mtypes Mtypes WHERE (Finances.membership_id = :c0 AND Finances.created < :c1) ORDER BY Finances.enddate DESC LIMIT 1 because it's left out the Finances table and ignored the ->contain() Should I be querying the Finance model or is there something else missing?
# Jun 27th 2018, 09:11 itamer Hi, probably a similar type of problem, maintaining some code that I suspect hasn't worked since it was upgraded from Cake1 to Cake3. Mtypes (Membership types) have many Finances (payments) - set up in the Table If I call $data['mtype'] = $this->Mtypes->find() ->select(['name']) ->contain(['Finances']) ->where(['Finances.membership_id'=>$data['membership_id'], 'Finances.created <' => $data['created']])