Coder Social home page Coder Social logo

Q: doctrine usage about php-json-api HOT 5 OPEN

nilportugues avatar nilportugues commented on June 14, 2024
Q: doctrine usage

from php-json-api.

Comments (5)

basz avatar basz commented on June 14, 2024

i see this is actually an issue with your serialiser nilportugues/php-serializer#14

from php-json-api.

basz avatar basz commented on June 14, 2024

Perhaps not : The JsonApiSerializer extends DeepCopySerializer which doesn't seem to protect against circular dependencies...

from php-json-api.

nilportugues avatar nilportugues commented on June 14, 2024

Circular dependencies are bad design.

I can code against bad design, but it really introduces lots of complexity to the library to support a bad practice.

from php-json-api.

basz avatar basz commented on June 14, 2024

Hi, I rather do it right then wrong... But I would argue circular dependencies aren't bad design perse. They exist in doctrine entities. Think of a one to many relationship. Although I am never interested in traversing the identity from a Preference. I want the relationship defined in the owning side (preference) becuase of the constained advantage the cascade option gives me. (When ever I remove a user all his preferences are also deleted.)

ps. Simply changing the DeepCopySericalizer to Serializer fixed this...

<?xml version="1.0"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
  <entity name="Identity">
    <id name="id" type="integer">
      <generator strategy="AUTO"/>
    </id>
    <field name="name" type="string" length="255" nullable="true"/>
    <one-to-many field="preference" target-entity="Preference" mapped-by="identity"/>
  </entity>
</doctrine-mapping>

<?xml version="1.0"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
  <entity name="Preference">
    <id name="id" type="integer">
      <generator strategy="AUTO"/>
    </id>
    <field name="name" type="string" length="255" nullable="true"/>
    <many-to-one field="identity" target-entity="Identity" inversed-by="preference">
      <join-columns>
        <join-column name="identity_id" referenced-column-name="id" on-delete="CASCADE"/>
      </join-columns>
    </many-to-one>
  </entity>
</doctrine-mapping>

from php-json-api.

basz avatar basz commented on June 14, 2024

thoughts? advise? still stuck at serialising entities

from php-json-api.

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.