I am using cakephp to run a query, this query consists of custom derived fields as well as some that are in the table.
Cake returns the ones in the table in its own array and the others in an array key of 0 - essentially splitting my results which afterwards I then have to merge together.
I know I can use virtual fields to put the derived fields in to the main array however they are very custom and can change a lot, so it is not suitable to put these fields as virtual fields.
What I'd like is an option of some sort so that cakephp just returns everything in to the 0 key of the array. Something like $this->Model->find('all',$options,RTN_FLAT_ARRAY)
Is something like this already possible?
This does not make any sense as it would break your result. You're using the "all" find. So it is expected that it will return 0, 1, 2... records in the array not just one record. If you flatten this you get just one record and lose all others.
Use "first" instead and put your custom fields inside the record it will return. You can use the afterFind() callback of the model to modify the result sets.
Also I would not flatten the array, the structure is there for a certain reason. Everything in CakePHP follows conventions. So for example the result will match your form fields when you set them. If you change that structure you'll have to do a lot more manual work in other places. Follow the conventions, they're there for a reason.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With