1

In my project with Symfony2, I'm using Doctrine createNativeQuery, and I would like to get an associative array.

This is my code

$rsm = new ResultSetMapping;
$rsm->addScalarResult('id', 'id');
$rsm->addScalarResult('name', 'name');
$rsm->addScalarResult('phone_one', 'phoneOne');
$rsm->addScalarResult('phone_two', 'phoneTwo');

I have this result:

array:2 [
    0 => array:4 [
        "id" => "975"
        "name" => "one name"
        "phoneOne" => "122345556"
        "phoneTwo" => "345566789"
    ]
  1 => array:4 [
    0 => array:4 [
        "id" => "976"
        "name" => "two name"
        "phoneOne" => "122345556"
        "phoneTwo" => "345566789"
    ]
]

It's posible this result?

array:2 [
    0 => array:4 [
        "id" => "975"
        "name" => "one name"
        "phones" => [
            "phoneOne" => "122345556"
            "phoneTwo" => "345566789"
        ]
    ]
  1 => array:4 [
    0 => array:4 [
        "id" => "976"
        "name" => "two name"
        "phones" => [
            "phoneOne" => "122345556"
            "phoneTwo" => "345566789"
        ]
    ]
]

Thanks a lot

jjgarcía
  • 589
  • 1
  • 4
  • 26

1 Answers1

1

If that is the result you want, why not create a OneToMany for Users to Phones? I would highly suggest you do that.

Johnny
  • 559
  • 9
  • 17