Wednesday, May 13, 2015

Avoid converting date/datetime fields to Cake/Time instances with CakePHP 3

First off, sorry for the "question spam". I'm just posting all issues of the last two weeks in a short period of time. I hope that this isn't disturbing anyone.

While trying to figure how to use combine with collections and entities (is in other thread) I didn't found an easy way to avoid date / datetime fields of DB been converted to Time instances.

$query->hydrate(false);

Didn't work, date / datetime field is also converted to a Cake/Time instance

There exists an easy way to avoid that conversion?

I was forced to do something like this in the collection to use combine or indexBy groupBy collection functions with date fields:

            ->each(function ($entity){
                $entity
->dateStr = $entity->date->toDateString();
               
return $entity;
           
})
            ->combine('dateStr', 'id')
            ->indexBy('dateStr')
           
->GroupBy('dateStr')

Cheers.

--
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: