Only use RAW SQL if really nescessary
First of all, try to avoid using RAW SQL queries unless there's really no other option. Also, when using RAW SQL, keep in mind that you will have to sanitize your queries yourself to prevent SQL injection. Since you're dealing with payment information, please double check that you're escaping $initialDate
and $finalDate
, because I don't see any security measures in your code.
Formatting the results
To get the results the way you want, you'll have to use aliases for your fields in a 'special' format;
SELECT
myfield AS "Mymodel__somefield",
myotherfield AS "Mymodel__someotherfield"
FROM .....
note there should be two underscores between Mymodel
and fieldname
Should return;
array (
0 => array(
'Mymodel' => array (
'somefield' => 'foo',
'otherfield' => 'bar',
)
)
)