How To Store EAV Data When It Has Nested Objects/Entities












0















I have json data that have both nested objects and attributes. Eg of one json object:



(After json_decode into an array:)



Array
(
[attributename1] => attributevalue1
[attributename2] => attributevalue2
[NestedEntity1] => Array (

[0] => Array (
[attributename1] => attributevalue1
[attributename2] => attributevalue2
)
[1] => Array (
[attributename1] => attributevalue1
[attributename2] => attributevalue2
)
[2] => Array (
[attributename1] => attributevalue1
[attributename2] => attributevalue2
[NestedEntity1.2] => Array (

[0] => Array (
[attributename1] => attributevalue1
[attributename2] => attributevalue2
)
[1] => Array (
[attributename1] => attributevalue1
[attributename2] => attributevalue2
)

)

)

) )


Note: entities can be further nested in nested entities



My question is: How can I store this data into MySQL?



If it's just attributes, it's easy with a table in MySQL set up for EAV data. But if I have nested objects, I am quite lost as to how to store this. An important thing is that I'd have to be able to pivot the table and make queries like "SELECT * FROM entity WHERE A LIKE B etc.



I suspect I might have to split the nested entities into new tables of their own, then create one-to-many relationship between the "parent" and "child". However:
(1) I have no clue as to do this such that any json data can be accomodated. This probably means some program has to detect automatically a nested object.
(2) ALthough I am open to populating the data form a single json object into multiple tables, one representing each (nested) entity, I was thinking if it might be possible to populate everything into a single table in MySQL. This would prevent the need for creating new table schemas when the need arises.









share







New contributor




forgodsakehold is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    0















    I have json data that have both nested objects and attributes. Eg of one json object:



    (After json_decode into an array:)



    Array
    (
    [attributename1] => attributevalue1
    [attributename2] => attributevalue2
    [NestedEntity1] => Array (

    [0] => Array (
    [attributename1] => attributevalue1
    [attributename2] => attributevalue2
    )
    [1] => Array (
    [attributename1] => attributevalue1
    [attributename2] => attributevalue2
    )
    [2] => Array (
    [attributename1] => attributevalue1
    [attributename2] => attributevalue2
    [NestedEntity1.2] => Array (

    [0] => Array (
    [attributename1] => attributevalue1
    [attributename2] => attributevalue2
    )
    [1] => Array (
    [attributename1] => attributevalue1
    [attributename2] => attributevalue2
    )

    )

    )

    ) )


    Note: entities can be further nested in nested entities



    My question is: How can I store this data into MySQL?



    If it's just attributes, it's easy with a table in MySQL set up for EAV data. But if I have nested objects, I am quite lost as to how to store this. An important thing is that I'd have to be able to pivot the table and make queries like "SELECT * FROM entity WHERE A LIKE B etc.



    I suspect I might have to split the nested entities into new tables of their own, then create one-to-many relationship between the "parent" and "child". However:
    (1) I have no clue as to do this such that any json data can be accomodated. This probably means some program has to detect automatically a nested object.
    (2) ALthough I am open to populating the data form a single json object into multiple tables, one representing each (nested) entity, I was thinking if it might be possible to populate everything into a single table in MySQL. This would prevent the need for creating new table schemas when the need arises.









    share







    New contributor




    forgodsakehold is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      0












      0








      0








      I have json data that have both nested objects and attributes. Eg of one json object:



      (After json_decode into an array:)



      Array
      (
      [attributename1] => attributevalue1
      [attributename2] => attributevalue2
      [NestedEntity1] => Array (

      [0] => Array (
      [attributename1] => attributevalue1
      [attributename2] => attributevalue2
      )
      [1] => Array (
      [attributename1] => attributevalue1
      [attributename2] => attributevalue2
      )
      [2] => Array (
      [attributename1] => attributevalue1
      [attributename2] => attributevalue2
      [NestedEntity1.2] => Array (

      [0] => Array (
      [attributename1] => attributevalue1
      [attributename2] => attributevalue2
      )
      [1] => Array (
      [attributename1] => attributevalue1
      [attributename2] => attributevalue2
      )

      )

      )

      ) )


      Note: entities can be further nested in nested entities



      My question is: How can I store this data into MySQL?



      If it's just attributes, it's easy with a table in MySQL set up for EAV data. But if I have nested objects, I am quite lost as to how to store this. An important thing is that I'd have to be able to pivot the table and make queries like "SELECT * FROM entity WHERE A LIKE B etc.



      I suspect I might have to split the nested entities into new tables of their own, then create one-to-many relationship between the "parent" and "child". However:
      (1) I have no clue as to do this such that any json data can be accomodated. This probably means some program has to detect automatically a nested object.
      (2) ALthough I am open to populating the data form a single json object into multiple tables, one representing each (nested) entity, I was thinking if it might be possible to populate everything into a single table in MySQL. This would prevent the need for creating new table schemas when the need arises.









      share







      New contributor




      forgodsakehold is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I have json data that have both nested objects and attributes. Eg of one json object:



      (After json_decode into an array:)



      Array
      (
      [attributename1] => attributevalue1
      [attributename2] => attributevalue2
      [NestedEntity1] => Array (

      [0] => Array (
      [attributename1] => attributevalue1
      [attributename2] => attributevalue2
      )
      [1] => Array (
      [attributename1] => attributevalue1
      [attributename2] => attributevalue2
      )
      [2] => Array (
      [attributename1] => attributevalue1
      [attributename2] => attributevalue2
      [NestedEntity1.2] => Array (

      [0] => Array (
      [attributename1] => attributevalue1
      [attributename2] => attributevalue2
      )
      [1] => Array (
      [attributename1] => attributevalue1
      [attributename2] => attributevalue2
      )

      )

      )

      ) )


      Note: entities can be further nested in nested entities



      My question is: How can I store this data into MySQL?



      If it's just attributes, it's easy with a table in MySQL set up for EAV data. But if I have nested objects, I am quite lost as to how to store this. An important thing is that I'd have to be able to pivot the table and make queries like "SELECT * FROM entity WHERE A LIKE B etc.



      I suspect I might have to split the nested entities into new tables of their own, then create one-to-many relationship between the "parent" and "child". However:
      (1) I have no clue as to do this such that any json data can be accomodated. This probably means some program has to detect automatically a nested object.
      (2) ALthough I am open to populating the data form a single json object into multiple tables, one representing each (nested) entity, I was thinking if it might be possible to populate everything into a single table in MySQL. This would prevent the need for creating new table schemas when the need arises.







      mysql eav





      share







      New contributor




      forgodsakehold is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      forgodsakehold is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      forgodsakehold is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 2 mins ago









      forgodsakeholdforgodsakehold

      111




      111




      New contributor




      forgodsakehold is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      forgodsakehold is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      forgodsakehold is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "182"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          forgodsakehold is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f228175%2fhow-to-store-eav-data-when-it-has-nested-objects-entities%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          forgodsakehold is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          forgodsakehold is a new contributor. Be nice, and check out our Code of Conduct.













          forgodsakehold is a new contributor. Be nice, and check out our Code of Conduct.












          forgodsakehold is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Database Administrators Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f228175%2fhow-to-store-eav-data-when-it-has-nested-objects-entities%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          الفوسفات في المغرب

          Four equal circles intersect: What is the area of the small shaded portion and its height

          جامعة ليفربول