question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

related entities not loaded?

See original GitHub issue

My entity has a Many2One relationship

    /**
     * @var Industry
     *
     * @ORM\ManyToOne(targetEntity="Industry", fetch="EAGER")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="IndustryId", referencedColumnName="Id")
     * })
     */
    private $industry;

But when requesting from this resource, the related entities are not fetched.

The results would only include:

  "industry": "/api/industries/1",

Instead of the whole entity.

I’m using the default configuration

eager_loading:
        # To enable or disable eager loading.
        enabled: true

        # Fetch only partial data according to serialization groups.
        # If enabled, Doctrine ORM entities will not work as expected if any of the other fields are used.
        fetch_partial: false

        # Max number of joined relations before EagerLoading throws a RuntimeException.
        max_joins: 30

        # Force join on every relation.
        # If disabled, it will only join relations having the EAGER fetch mode.
        force_eager: true

which makes the fetch="EAGER" annotation redundant, yet I added it to see if it made any difference.

I could only got to get the related entities by creating a serialization group and adding each of the properties on the related entity to that group. While it works, it seems a bit convoluted, and from what I gathered from documentation and configuration the relationships were going to be forced to be eager by API-Platform.

Am I missing something here?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
fyryecommented, May 17, 2019

@ismail1432 I believe they are looking for something similar to #284 I answered the OP’s question involving serializer groups on SO, if that provides some more context.

They were expecting api-platform to automatically embed all related entity association properties, with the force_eager=true option, assuming it to mean force_embed=true.

0reactions
yivicommented, May 20, 2019

Yeah, I had completely misread the docs.  😨

Off I go to create many serialization groups to cover all the required possibilities.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Entity Framework not loading related objects - Stack Overflow
My problem is, it seems to get a list of records back, but related items are not loaded. My 'Transformer.UnpackTask' method takes the...
Read more >
Loading Related Entities - EF6 - Microsoft Learn
Eager loading is the process whereby a query for one type of entity also loads related entities as part of the query. Eager...
Read more >
Entity Framework Core 5 – Pitfalls To Avoid and Ideas to Try
Queries not including related data. EF Core moved away from lazy loading as a default feature. Navigation properties still exist as part of ......
Read more >
Explicit Loading Related Entities in EF 6 and EF Core
Here you will learn how to load related entities in an entity graph explicitly. Explicit loading is valid in EF 6 and EF...
Read more >
Blog App – Reading Related Data using .NET EF Core
In this case, firstly, a principal entity is loaded, but related data is not loaded at that time. Then a navigation property can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found