# |
Jan 12th 2018, 16:36 |
beakman |
Or some sorta join which would might end up a bit more efficient. |
# |
Jan 12th 2018, 16:35 |
beakman |
@bigdaddygee Might be able to shove a subquery somewhere in there too. |
# |
Jan 12th 2018, 16:35 |
bigdaddygee |
Maybe yes, but I just don't understand why this not working. but thanks :slightly_smiling_face: |
# |
Jan 12th 2018, 16:35 |
beakman |
https://book.cakephp.org/3.0/en/orm/behaviors/counter-cache.html |
# |
Jan 12th 2018, 16:34 |
beakman |
@bigdaddygee Might just want to use a counter cache for that. |
# |
Jan 12th 2018, 16:31 |
bigdaddygee |
``` $Stores = $this->Stores ->find() ->select(['UserStores.Count' => function(\Cake\ORM\Query $q) { return $q->func()->count('*'); }]) ->contain([ 'CreatedByUsers', 'ModifiedByUsers', 'Users', 'UserStores', 'Images' ]); ``` |
# |
Jan 12th 2018, 16:31 |
bigdaddygee |
Humm, do someone know how I can inject a count of another table into a resultset ? (Actualy I got the list instead of the count) |
# |
Jan 12th 2018, 16:19 |
neon1024 |
https://book.cakephp.org/3.0/en/orm/query-builder.html#automatically-creating-in-clauses |
# |
Jan 12th 2018, 16:18 |
danishkhan3621 |
is there any link of tutorials where i can get fetching result of these types. |
# |
Jan 12th 2018, 16:17 |
neon1024 |
Still, at least there is finally a `.forEach()` |
# |
Jan 12th 2018, 16:16 |
neon1024 |
Well, I suppose technically it’s a hash of objects as strictly speaking Javascript doesn’t have arrays |
# |
Jan 12th 2018, 16:16 |
danishkhan3621 |
@neon1024: Thanks |
# |
Jan 12th 2018, 16:15 |
neon1024 |
So you’ll have to fix that ;) |
# |
Jan 12th 2018, 16:15 |
neon1024 |
It’s an array of objects |
# |
Jan 12th 2018, 16:15 |
neon1024 |
What you’ve got there is JSON |
# |
Jan 12th 2018, 16:14 |
neon1024 |
This is not an array unfortunatly, `My array is [{"category_id":1},{"category_id":4}] ` |
# |
Jan 12th 2018, 16:14 |
neon1024 |
Yeah, of course |
# |
Jan 12th 2018, 16:14 |
danishkhan3621 |
this does not return any result because i have to assign category_id key to an array |
# |
Jan 12th 2018, 16:13 |
danishkhan3621 |
@neon1024: `$get_all_categories_prd_id = $this->Products->find('all',array('conditions'=>array('category_id IN'=>$get_all_categories_p_id)));` |
# |
Jan 12th 2018, 16:10 |
neon1024 |
But that’s personal preference |
# |
Jan 12th 2018, 16:10 |
neon1024 |
You should also really consider changing your variable names to use the CakePHP coding standard |
# |
Jan 12th 2018, 16:10 |
danishkhan3621 |
@neon1024: is there any other way to do it without loop. |
# |
Jan 12th 2018, 16:09 |
neon1024 |
There is also no need to use a loop, as you can just transform the array and use `'id IN' => $array` |
# |
Jan 12th 2018, 16:09 |
neon1024 |
You should also not use `count()` in a for loop as it causes count to be executed in every iteration |
# |
Jan 12th 2018, 16:08 |
neon1024 |
If your array is JSON, you might struggle to use it in PHP ;) |
# |
Jan 12th 2018, 16:08 |
neon1024 |
<- Click the [+] button and click on the ‘Code or text snippet’ |
# |
Jan 12th 2018, 16:02 |
danishkhan3621 |
How can i run find query to search records from an array : My array is [{"category_id":1},{"category_id":4}] and i'm running query like this for($i=0; $i<count($get_all_categories_p_id); $i++) { $get_all_categories_prd_id = $this->Products->find('all',array('conditions'=>array('category_id IN'=>$get_all_categories_p_id[$i]['category_id']))); $product_List[]=$get_all_categories_prd_id; } |
# |
Jan 12th 2018, 15:34 |
jotpe |
is there any possibility to run composers `post-update-cmd` for _production_ or _development_? |
# |
Jan 12th 2018, 15:22 |
xavier83ar |
ok, thanks! |
# |
Jan 12th 2018, 15:20 |
jota |
then rollback |
# |
Jan 12th 2018, 15:20 |
jota |
got the query |
# |
Jan 12th 2018, 15:20 |
jota |
@xavier83ar use a begin tran. |
# |
Jan 12th 2018, 15:19 |
dereuromark |
without actual params |
# |
Jan 12th 2018, 15:19 |
dereuromark |
debug((string)$query) only shows the query |
# |
Jan 12th 2018, 15:19 |
jota |
You could use a begin trans... without commit. |
# |
Jan 12th 2018, 15:19 |
dereuromark |
This was the issue to it xavier: https://github.com/cakephp/debug_kit/issues/568 |
# |
Jan 12th 2018, 15:18 |
jotpe |
@learningcake: this one is good: https://paulund.co.uk/datetime-php otherwise you can also use Cake's Time Utility: https://book.cakephp.org/3.0/en/core-libraries/time.html |
# |
Jan 12th 2018, 15:15 |
xavier83ar |
I need run a deleteAll() query, and I want to check the query that the orm will run |
# |
Jan 12th 2018, 15:13 |
xavier83ar |
Hi, is there a way of getting the plain sql that the ORM will run without actually running it? |
# |
Jan 12th 2018, 15:12 |
learningcake |
my bad |
# |
Jan 12th 2018, 15:11 |
learningcake |
Thank you. works now |