Wednesday, February 5, 2014

Move aggregated column values into model's array

With this find I am actually joining across several tables, and in case of the test data I have pasted there was no related record so the values are all nulls. This is not an issue. Here is some idea of the code:

      $options['fields'] = array(
                'Audit.event',
                'Audit.model',
                'Audit.entity_id',
                'Audit.json_object',
                'Audit.description',
                'Audit.source_id',
                'max(Audit.created) AS created',
      );

      $businesses = $this->Business->find('all', $options);

Is it possible to move the resultant value for the aggregate column 'Audit.created' back into the correct place in the model's data array?

Instead of this:

[{
        "Audit" : {
            "id" : null,
            "event" : null,
            "model" : null,
            "entity_id" : null,
            "json_object" : null,
            "description" : null,
            "source_id" : null
        },
        "0" : {
            "Audit__Created" : null
        }
}]


I would like to make:

[{
        "Audit" : {
            "id" : null,
            "event" : null,
            "model" : null,
            "entity_id" : null,
            "json_object" : null,
            "description" : null,
            "source_id" : null,
            "created" : null
        }
}]


Thanks

Jake

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: