php - How to insert data in the nested set model(MySQL); -


in nested set model have left , right columns

the first time when table empty, need insert right column, if don't know how many children have

left 1 - forever

right ? - value goes here??

how make dynamic? not static.

ps: using php

i'm assuming tags , title looking solution works mysql.

yes, right unless know number of elements in advance value right needs calculated dynamically. there 2 approaches can use:

  • you start least value works (2 in case) , increase later needed.
  • you make guess 10000000 , hope that's enough, need prepared possibility wasn't enough , may need adjusting again later.

in both cases need implement left , right values multiple rows may need adjusted when inserting new rows, in second case need perform updates if guesses wrong. second solution more complex, can give better performance.

note of 4 common ways store heirarchical data, nested sets approach hardest perform inserts , updates. see slide 69 of bill karwin's models heirarchical data.

nested sets update difficulty


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -