# |
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 |
# |
Jul 17th 2018, 09:52 |
saeideng |
no |
# |
Jul 17th 2018, 09:52 |
josbeir |
just |
# |
Jul 17th 2018, 09:52 |
josbeir |
sorry |
# |
Jul 17th 2018, 09:52 |
saeideng |
view? |
# |
Jul 17th 2018, 09:51 |
josbeir |
true :slightly_smiling_face: |
# |
Jul 17th 2018, 09:51 |
josbeir |
ah in the view layer |
# |
Jul 17th 2018, 09:51 |
saeideng |
and `setErrors` |
# |
Jul 17th 2018, 09:51 |
saeideng |
`setError` |
# |
Jul 17th 2018, 09:51 |
josbeir |
i'm not sure tho, you should check the docs/code for that |
# |
Jul 17th 2018, 09:50 |
josbeir |
i don't think so |
# |
Jul 17th 2018, 09:46 |
abdualelah.mdy |
@josbeir can I mark both fields as error ? |
# |
Jul 17th 2018, 09:39 |
abdualelah.mdy |
Thank you very much :heart_eyes: |
# |
Jul 17th 2018, 09:39 |
neon1024 |
https://book.cakephp.org/3.0/en/orm/validation.html#creating-unique-field-rules |
# |
Jul 17th 2018, 09:39 |
josbeir |
add that to your buildRules method in your model |
# |
Jul 17th 2018, 09:38 |
josbeir |
$rules->add(new IsUnique([ 'field1, 'field2' ]), 'skuUnique', [ 'errorField' => 'field1', 'message' => __d('admin', 'The item already exists') ]); |
# |
Jul 17th 2018, 09:38 |
abdualelah.mdy |
I have question : How can I check if the combination of 2 columns in my table is unique ? |