0

Javascript: I have about ten objects. I need to store them in database (MySQL).

MyObject.create({
    id: 1,
    name: "object_1",
    ...
    buttons: [
         {
              name: "OK",
              action: "Accept"
         },
         {
              name: "No",
              action: "Cancel"
         }
    ]    
});

The database consists of: object table and objects-settings table. Now result is the next:

|  obj_id  |  prop  |  type  |  value    | 
|     1    |  id    |   int  |   1       | 
|     1    |  name  |   str  |  object_1 |
 ... 
|     2    |  id    |   int  |   2       | 
|     2    |  name  |   str  |  object_2 |

But i need to store hierarhy data in database. It looks like hierarhy menu or json. I don't want to use recursive functions on php. I have found this link, but can't understand it.

I it will be a table like (id, item, parent), how to build a sql query.

txid
  • 66
  • 7
  • Are you opposed to storing JSON strings in your database instead of trying to build a tree hierarchy in a single table? RDBMs are not really geared for storing/retrieving data in the way that you want. When you need to give the object back to JS then you can just echo the string which is stored in your DB. – MonkeyZeus Mar 26 '18 at 17:54
  • This is my favorite https://stackoverflow.com/q/20215744/4104224, especially it's second most up-voted answer, and that answer's link to http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/ – Uueerdo Mar 26 '18 at 18:02
  • @MonkeyZeus I will think about it. Thank you. – txid Mar 26 '18 at 18:02
  • @Uueerdo, Thank you. It is helpfull for me/ I'll try it. – txid Mar 26 '18 at 18:08

0 Answers0