# |
Nov 29th 2017, 21:50 |
inoas |
you can use formatResults as I said to tinker with the resultset and make it a single item |
# |
Nov 29th 2017, 21:09 |
saeideng |
first show your native sql |
# |
Nov 29th 2017, 21:08 |
saeideng |
if you need first first in joined table you can not IMO |
# |
Nov 29th 2017, 21:07 |
saeideng |
first on resultset |
# |
Nov 29th 2017, 21:07 |
joopm |
saeideng my query is more than complicated to not to konw how to use ->first() in simple query |
# |
Nov 29th 2017, 21:07 |
saeideng |
first on query |
# |
Nov 29th 2017, 21:06 |
saeideng |
because we have 2 first() |
# |
Nov 29th 2017, 21:06 |
inoas |
well that first() is probably a collection method or so |
# |
Nov 29th 2017, 21:06 |
inoas |
why the execute? |
# |
Nov 29th 2017, 21:06 |
saeideng |
limit(1)->execute()->first() :slightly_smiling_face: |
# |
Nov 29th 2017, 21:06 |
inoas |
or even run them in background mode to get 10 items and then cache them in the db to be consumed |
# |
Nov 29th 2017, 21:06 |
inoas |
basically to make web services that return data faster |
# |
Nov 29th 2017, 21:05 |
inoas |
I want to cache responses of Http\Client ... serialize a good thing? |
# |
Nov 29th 2017, 21:05 |
saeideng |
inoas |
# |
Nov 29th 2017, 21:05 |
saeideng |
https://api.cakephp.org/3.5/source-class-Cake.Datasource.QueryTrait.html#402-421 |
# |
Nov 29th 2017, 21:05 |
inoas |
saeideng you can use formatResults to get the first item only instead of list of 1 items |
# |
Nov 29th 2017, 21:05 |
saeideng |
$query->select(['id', 'username'])->first(); |
# |
Nov 29th 2017, 21:04 |
inoas |
saeideng yeah true |
# |
Nov 29th 2017, 21:04 |
joopm |
and in my case no other |
# |
Nov 29th 2017, 21:04 |
joopm |
or is there sometinh like matching but returns only the first? |
# |
Nov 29th 2017, 21:03 |
joopm |
and its part of a matching |
# |
Nov 29th 2017, 21:03 |
joopm |
i want only the first one |
# |
Nov 29th 2017, 21:02 |
saeideng |
this returns array of result |
# |
Nov 29th 2017, 21:02 |
joopm |
but using ->first() there |
# |
Nov 29th 2017, 21:02 |
joopm |
this is the condition for the query |
# |
Nov 29th 2017, 21:02 |
joopm |
->where(['AND'=>[['Applications.state_id'=>2],['user_id'=>$this->Auth->User('id')]]]) //here does not works first();} |
# |
Nov 29th 2017, 21:02 |
joopm |
i know that first return result not query |
# |
Nov 29th 2017, 21:01 |
joopm |
Query builder for association "Applications" did not return a query |
# |
Nov 29th 2017, 21:01 |
saeideng |
first return result not query |
# |
Nov 29th 2017, 21:01 |
joopm |
first would be good but its says no query return |
# |
Nov 29th 2017, 21:00 |
saeideng |
first returns "item" |
# |
Nov 29th 2017, 20:59 |
saeideng |
limit returns [0 => item] |
# |
Nov 29th 2017, 20:59 |
saeideng |
limit and first different |
# |
Nov 29th 2017, 20:58 |
saeideng |
inoas |
# |
Nov 29th 2017, 20:55 |
inoas |
first() will execute which seems is not what you want (you want to return the query object) |
# |
Nov 29th 2017, 20:55 |
inoas |
joopm limit(1) |
# |
Nov 29th 2017, 20:55 |
saeideng |
or limit(1) |
# |
Nov 29th 2017, 20:54 |
saeideng |
first() |
# |
Nov 29th 2017, 20:54 |
obinoob |
joopm: you only need to save one registry right? |
# |
Nov 29th 2017, 20:53 |
joopm |
but i dont need to get the first element of array i just need one element |
# |
Nov 29th 2017, 20:53 |
saeideng |
and save with save entities() |