Coder Social home page Coder Social logo

Embedded relations about core HOT 8 CLOSED

api-platform avatar api-platform commented on July 28, 2024
Embedded relations

from core.

Comments (8)

dunglas avatar dunglas commented on July 28, 2024

Can you create a gist with your entity classes?

from core.

theofidry avatar theofidry commented on July 28, 2024

Sure: https://gist.github.com/47f5040f01a265921048.git.

from core.

dunglas avatar dunglas commented on July 28, 2024

Does #64 fix the issue?

from core.

theofidry avatar theofidry commented on July 28, 2024

Problem solved thanks again and sorry for the late check!

from core.

theofidry avatar theofidry commented on July 28, 2024

Seems like a was a bit too hasty. But it's rather a question than an issue. I get the expected behaviour with the following declaration:

resource.job:
    parent:    api.resource
    arguments: [ ApiBundle\Entity\Job ]
    calls:
        - method:    initNormalizationContext
          arguments: [ { groups: [ user ] } ]
    tags:      [ { name: api.resource } ]

resource.mandate:
    parent:    api.resource
    arguments: [ ApiBundle\Entity\Mandate ]
    tags:      [ { name: api.resource } ]

resource.user:
    parent:    api.resource
    arguments: [ ApiBundle\Entity\User ]
    calls:
        - method:    initNormalizationContext
          arguments: [ { groups: [ user ] } ]
    tags:      [ { name: api.resource } ]

As you can see I added the normalization context in both User and Jobs. I that the expected behaviour?

I first thought than when you were using a context it applied on all entities, i.e. if I have a relation between User - Job - Mandate and when I get Users with a user context, it will show only the attributes on which the serialization group user is applied but for the three entities.

Besides solving my problem this way causes another problem. Indeed if I check Job, then now the

{
    "@context": "\/api\/contexts\/Job",
    "@id": "\/api\/jobs\/1",
    "@type": "Job",
    "title": "Resident Agitator",
    "abbreviation": "IU",
    "enabled": true,
    "user": {"all the attributes matching the `user` serialization group are shown, basically it's the same object as when I directly request the user endpoint."},
    "mandate": null
}

Instead of the wished result:

{
    "@context": "\/api\/contexts\/Job",
    "@id": "\/api\/jobs\/1",
    "@type": "Job",
    "title": "Resident Agitator",
    "abbreviation": "IU",
    "enabled": true,
    "user": "\/api\/users\/43",
    "mandate": null
}

from core.

dunglas avatar dunglas commented on July 28, 2024

It's a bug. The intended behavior is the one you described.

from core.

sebdec avatar sebdec commented on July 28, 2024

hello
I still reproduce the issue
It seems the serialization groups in relations are not managed correctly

there is a pending fix about it ?

Thank you

from core.

teohhanhui avatar teohhanhui commented on July 28, 2024

@sebdec This issue is about v1.0, which means it's really old and lots of things have changed since then. Please open a new issue (if there is not already one).

from core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.