# |
Jul 17th 2018, 11:32 |
lorenzo |
https://book.cakephp.org/3.0/en/orm/query-builder.html#using-sql-functions |
# |
Jul 17th 2018, 11:31 |
edgaras.jan |
> Order fields/directions are not sanitized by the query builder. > You should use a whitelist of fields/directions when passing > in user-supplied data to `order()`. |
# |
Jul 17th 2018, 11:31 |
lorenzo |
@johnwayne use the functions builder |
# |
Jul 17th 2018, 11:31 |
edgaras.jan |
`->order(['duration' => $this->getRequest()->getQuery('direction')])` is insecure |
# |
Jul 17th 2018, 11:23 |
josbeir |
:P |
# |
Jul 17th 2018, 11:23 |
neon1024 |
Yeah, but currently I only need it in that one place ;) #lazy |
# |
Jul 17th 2018, 11:23 |
johnwayne |
Is there a way to integrate in cakephp query '->where([CAST(id / POW(3, CAST(LOG10(id) AS SIGNED)) AS SIGNED) = $myId])' |
# |
Jul 17th 2018, 11:22 |
josbeir |
you will get that value everywhere you need it |
# |
Jul 17th 2018, 11:22 |
josbeir |
i'm still conviced that, in your case @neon1024 it would be cleaner to also store the duration in db |
# |
Jul 17th 2018, 11:21 |
neon1024 |
Depending on what it is and what data it involves of course |
# |
Jul 17th 2018, 11:20 |
neon1024 |
Yeah, if you can’t do the calc in SQL, it’s probably worth storing it |
# |
Jul 17th 2018, 11:19 |
josbeir |
(or store the calculated field in db too) |
# |
Jul 17th 2018, 11:19 |
neon1024 |
If you want to use PHP, you’d probably need to look into paginating a collection |
# |
Jul 17th 2018, 11:18 |
neon1024 |
I’m not convinced you can’t calculate in SQL, it’s pretty well featured |
# |
Jul 17th 2018, 11:18 |
josbeir |
@dereuromark did you find it? |
# |
Jul 17th 2018, 11:13 |
matt |
I was thinking I need to get all the results from the query, map in my calculated value and then paginate the results myself using collection take etc |
# |
Jul 17th 2018, 11:12 |
matt |
thanks though my problem is I can't calculate the field using sql |
# |
Jul 17th 2018, 11:11 |
neon1024 |
You probably only really need lines 3 and 6-8 |
# |
Jul 17th 2018, 11:11 |
neon1024 |
File uploaded https://cakesf.slack.com/files/U1BT622HW/FBT5SFH6J/sorting_on_calculated_field.php / https://slack-files.com/T053DPNCM-FBT5SFH6J-9f79beece9 - This is for the Crud plugin, but the query instance is the same either way. |
# |
Jul 17th 2018, 11:09 |
matt |
thanks @neon1024 - how did you append the calculated field to the query? |
# |
Jul 17th 2018, 11:00 |
neon1024 |
I just wrote a conditional in my controller, to check for the sort field, and then appended my calculated field onto the query |
# |
Jul 17th 2018, 11:00 |
neon1024 |
Heh, I did this yesterday, but it was a bit hackish |
# |
Jul 17th 2018, 10:26 |
matt |
Hi, I'm using cake pagination but I need to filter the results on a calculated field (I'm calculating a value for each of the results which I can't do with sql). What's the best way to paginate these results? Seems standard pagination isn't suitable as that relies on adding a limit field to the sql. thanks |
# |
Jul 17th 2018, 10:12 |
josbeir |
that should be a good thing tho |
# |
Jul 17th 2018, 10:12 |
josbeir |
yes but i think that its still untouched in the afterSave callback and only reset set correctly after |
# |
Jul 17th 2018, 10:12 |
tim |
@josbeir Yes it is set to false once it's saved |
# |
Jul 17th 2018, 10:11 |
dereuromark |
let me check |
# |
Jul 17th 2018, 10:06 |
josbeir |
i'm looking at Table::_onSaveSuccess |
# |
Jul 17th 2018, 10:06 |
josbeir |
so it should be still as is when you do stuff no +? |
# |
Jul 17th 2018, 10:06 |
josbeir |
but i see it happens after the event callback |
# |
Jul 17th 2018, 10:06 |
dereuromark |
would be nice to have this back |
# |
Jul 17th 2018, 10:05 |
dereuromark |
exactly, that is resettet, as such it cant help |
# |
Jul 17th 2018, 10:05 |
josbeir |
@dereuromark isn't the isNew() property set to false after the afterSave() |
# |
Jul 17th 2018, 10:05 |
snake-venom |
if i will develop a large application in cakephp 3 then if they cakephp 4 released then how much it will tough/ feasible to update from cakephp 3 to cakephp 4 ? |
# |
Jul 17th 2018, 10:01 |
dereuromark |
would be nice to have this in options or sth |
# |
Jul 17th 2018, 10:01 |
dereuromark |
I guess I have to also use beforeSave then and a model prop? |
# |
Jul 17th 2018, 10:01 |
dereuromark |
in 2.x we new with $created in afterSave callback if added or modified. In 3.x there seems to be nothing here anymore, right? |
# |
Jul 17th 2018, 09:52 |
josbeir |
just, post validation |
# |
Jul 17th 2018, 09:52 |
josbeir |
indeed |
# |
Jul 17th 2018, 09:52 |
saeideng |
model |
# |
Jul 17th 2018, 09:52 |
josbeir |
after retrieval :P |