0

I'm using CakeORM as a standalone on my project, it is working perfectly but there is something that didnt make much sense to me. Whenenver i select a date or boolean field from the joined table if is stored in a different way.

$users = TableRegistry::get('users')->find();
$users
->hydrate()
->select([
    'user_id',
    'username',
    'dt_last_login'
])
->toArray();

This code will get me something like this:

Array
(
    [0] => Array
        (
            [user_id] => 1
            [username] => 'teste'
            [dt_last_login] => DateTime Object
                (
                    [date] => 2016-08-23 08:42:54.000000
                    [timezone_type] => 3
                    [timezone] => America/Sao_Paulo
                )
        )
)

Ok, this is the expected behavior, now this next code has a different behavior.

$users = TableRegistry::get('users')->find();
$users
->hydrate()
->select([
    'user_id',
    'username',
    'dt_last_login',
    'dt_update' => 'users_update.dt_update'
])
->join([
    'table' => 'users_update',
    'type' => 'left',
    'conditions' => ['users.user_id = users_update.user_id']
])
->toArray();

With this piece of code i get something like this:

Array
(
    [0] => Array
        (
            [user_id] => 1
            [username] => 'teste'
            [dt_last_login] => DateTime Object
                (
                    [date] => 2016-08-23 08:42:54.000000
                    [timezone_type] => 3
                    [timezone] => America/Sao_Paulo
                )
            [dt_update] => 2016-08-23 08:42:54.000000
        )
)

As you can see, dt_last_login is a DateTime Object and dt_update is a string. Is there any way to make Cake fetch dt_update as a DateTime Object?

  • Sounds like **http://stackoverflow.com/questions/35650306/cakephp-3-x-how-to-change-the-data-type-of-a-selcted-alias** to me. – ndm Aug 23 '16 at 14:19
  • it actually is, just tried it and it worked :) ty –  Aug 23 '16 at 14:49

0 Answers0