PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 20, 2022

[FIXED] CakePHP 3 : Modifying Find Data

 January 20, 2022     cakephp, cakephp-3.0     No comments   

Issue

I currently have in CakePHP 3 a table called Tickets that has a few flags such as head_ticket and latest_ticket. Essentially when ever I edit a record I create a new row (a uuid field keeps the records linked together) and set the latest_ticket flag to true as this row contains the latest information.

What I would like to know is that is there a way I can do something in the find where I can get all the records that have the head_ticket set to true but update the head ticket data columns returned on-the-fly with the latest data from the row that has the latest_ticket flag set to true at the same time? It's almost like an afterFind scenario but one which has been deprecated in CakePHP 3

Thanks


Solution

Read the migration guide, it contains the answer to your question and probably more things you want and should to know when coming from 2.x:

Using the Modifying Results with Map/Reduce features of the ORM allow you to build aggregated data from your results, which is another use case that the afterFind callback was often used for.

The documentation about Map/Reduce contains an example for result set aggregation based on some filter, I think this is pretty much what you want.



Answered By - floriank
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing