Sure,
Il giorno lunedì 14 aprile 2014 11:40:53 UTC+2, José Lorenzo ha scritto:
-- I'm trying to add 'content' properties to main Entity properties (it's an exercise to collpase entities properties in an array)
[
(int) 0 => object(App\Model\Entity\Object) {
'new' => false,
'accessible' => [
'*' => true
],
'properties' => [
'id' => (int) 5,
'object_type_id' => (int) 12,
'status' => 'on',
'created' => object(DateTime) {
date => '2014-03-07 09:21:29'
timezone_type => (int) 3
timezone => 'Europe/Rome'
},
'modified' => object(DateTime) {
date => '2014-04-07 23:32:48'
timezone_type => (int) 3
timezone => 'Europe/Rome'
},
'start_date' => null,
'end_date' => null,
'subject' => null,
'abstract' => null,
'body' => null,
'duration' => null
],
'dirty' => [
'id' => true,
'start_date' => true,
'end_date' => true,
'subject' => true,
'abstract' => true,
'body' => true,
'duration' => true
],
'virtual' => [],
'errors' => [],
'repository' => 'ImageObjects'
}
]
This is the results of find all. In 'dirty' key you can see the 'content' properties that I add to App\Model\Entity\Object properties.
I unset the 'content' key so it isn't show in the above array.
I'm playing with ORM feature and I would want to know if formatResults is usable in query chain.
Il giorno lunedì 14 aprile 2014 11:40:53 UTC+2, José Lorenzo ha scritto:
Can you explain what you are trying to do? I'm not sure I get it from your code example.
On Monday, April 14, 2014 11:31:42 AM UTC+2, bato wrote:Hi,I'm trying to figure out if it's possible to use formatResults in custom finder methods to use ORM chain. I have seen in docs the example with mapper reducer.In my table object i havepublic findFlat($query, $options = []) {return $query->formatResults(function($results, $query) { return $results->map(function($row) {foreach ($row['content']->toArray() as $key => $value) {$row[$key] = $value;}unset($row['content']);return $row;});});}then in my controller I have$images = TableRegistry::get('ImageObjects'); $result = $images->find('flat');$result->contain(['Contents','Streams']); debug($result->toArray());In this way it works but if I add first()$result->first();then I obtain a fatal error in findFlat() methodError: Call to a member function toArray() on a non-objectAny help?Am I using wrong formatResults()? Is it possible to chain only mapper reducer?thanksalberto
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/d/optout.
No comments:
Post a Comment