getArrayResult on entity with ManyToOne association

前端 未结 2 1272
南旧
南旧 2021-01-17 18:33

Having the follow basic tables (one-to-many relationship)
Client - Has many users.
Users - Each user belongs to single client.

In a very simple exampl

相关标签:
2条回答
  • 2021-01-17 19:24

    As far as I know, you can't do this, because ClientID is not a property of User. User has a property like $client, and that client entity has an $id.

    This is confusing you because you're dealing with Entites but you're still thinking in SQL.

    The solution, though slightly less efficient, would probably be to join the Client entity into your DQL query, and then get $results[N]['client']['id'] (or similar, I'm not too familiar with getResultArray())

    0 讨论(0)
  • 2021-01-17 19:32

    Try to set the HINT_INCLUDE_META_COLUMNS query hint on the query (not the builder) before you execute it.

    $q->setHint(Query::HINT_INCLUDE_META_COLUMNS, true);
    
    0 讨论(0)
提交回复
热议问题