简体   繁体   中英

Doctrine Partials. Why ManyToOne or OneToMany fields are not displayed in the results?

I'm trying to use partials on an entity which contains a ManyToOne or OneToMany relation.

My DQL looks like this:

SELECT partial a.{created, updated} , partial b.{id, value, entity} FROM App\Entity\DataSetting a INNER JOIN a.fileEntityValues b

The problem is that "partial b" has a property called "entity" which is another field with relation defined like this.

/**
 * @ORM\ManyToOne(targetEntity="App\Entity\FileEntity")
 * @ORM\JoinColumn(name="file_entity_id", referencedColumnName="id")
 */
private $entity;

But when i execute the previous query I don't get errors but the "entity" field is just not displayed in the result:

[0]=>
  array(9) {
    ["id"]=>
    int(36)
    ["created"]=>
    object(DateTime)#3022 (3) {
      ["date"]=>
      string(26) "2020-12-31 00:00:00.000000"
      ["timezone_type"]=>
      int(3)
      ["timezone"]=>
      string(3) "UTC"
    }
    ["updated"]=>
    object(DateTime)#3021 (3) {
      ["date"]=>
      string(26) "2020-12-31 00:00:00.000000"
      ["timezone_type"]=>
      int(3)
      ["timezone"]=>
      string(3) "UTC"
    }
    ["fileEntityValues"]=>
    array(4) {
      [0]=>
      array(2) {
        ["id"]=>
        int(72)
        ["value"]=>
        string(4) "1112"
       // WHY entity field not displayed
      }
      [1]=>
      array(2) {
        ["id"]=>
        int(73)
        ["value"]=>
        string(4) "1111"
      }

WHY?

@claudio how did you print the debug output?

see, if you used dump(), or var_dump(), fileEntityValues.entities should be an ArrayCollection()

I guess you dumped an object serialization, excluding in some way fileEntityValues.entity

can you:

  • paste how you printed the debug
  • paste both entities, or at least the constructors
  • paste the result of dump($entity)

hint: don't use partials, they are in some way discouraged also by Doctrine and can lead to incoherent behaviors

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM