79890

How do I generate lft and rght values for a cakephp 2.0 tree?

Question:

I've read that if you have a model that $actsAs = array('Tree'), that you can simply set the parent_id for your seed data, and a call to $this->Model->recover() should generate the proper lft and rght values for you, but when I do this, Cake seems to generate random values every time. The values vary from very large (in the thousands) to negative values. I've checked for circular references and found none as well. What could be wrong here?

SQL:

create table menus ( id int auto_increment not null, parent_id int null , lft int null , rght int null , title varchar(1024) not null, path varchar(1024) not null, constraint pk_menus primary key (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; This is the seeded data: After one Model->recover() +----+-----------+------+------+ +----+-----------+------+------+ | id | parent_id | lft | rght | | id | parent_id | lft | rght | +----+-----------+------+------+ +----+-----------+------+------+ | 1 | NULL | NULL | NULL | | 1 | NULL | 595 | 619 | | 7 | 1 | NULL | NULL | | 7 | 1 | 619 | 567 | | 6 | 1 | NULL | NULL | | 6 | 1 | 627 | 595 | | 5 | 1 | NULL | NULL | | 5 | 1 | 600 | 621 | | 4 | 1 | NULL | NULL | | 4 | 1 | 603 | 621 | | 3 | 1 | NULL | NULL | | 3 | 1 | 619 | 529 | | 2 | 1 | NULL | NULL | | 2 | 1 | 595 | 529 | | 8 | 2 | NULL | NULL | | 8 | 2 | 627 | 628 | | 13 | 3 | NULL | NULL | | 13 | 3 | 595 | 567 | | 12 | 3 | NULL | NULL | | 12 | 3 | 627 | 621 | | 11 | 3 | NULL | NULL | | 11 | 3 | 595 | 631 | | 10 | 3 | NULL | NULL | | 10 | 3 | 604 | 529 | | 9 | 3 | NULL | NULL | | 9 | 3 | 595 | 567 | | 14 | 5 | NULL | NULL | | 14 | 5 | 628 | 629 | | 15 | 5 | NULL | NULL | | 15 | 5 | 567 | 529 | | 16 | 5 | NULL | NULL | | 16 | 5 | 619 | 600 | | 17 | 5 | NULL | NULL | | 17 | 5 | 627 | 605 | | 21 | 6 | NULL | NULL | | 21 | 6 | 567 | 619 | | 20 | 6 | NULL | NULL | | 20 | 6 | 595 | 567 | | 19 | 6 | NULL | NULL | | 19 | 6 | 619 | 600 | | 18 | 6 | NULL | NULL | | 18 | 6 | 567 | 529 | | 22 | 10 | NULL | NULL | | 22 | 10 | 567 | 619 | | 23 | 11 | NULL | NULL | | 23 | 11 | 64 | 621 | | 24 | 12 | NULL | NULL | | 24 | 12 | 627 | 621 | | 25 | 13 | NULL | NULL | | 25 | 13 | 605 | 595 | | 32 | 16 | NULL | NULL | | 32 | 16 | 628 | 627 | | 31 | 16 | NULL | NULL | | 31 | 16 | 567 | 619 | | 30 | 16 | NULL | NULL | | 30 | 16 | 64 | 621 | | 29 | 16 | NULL | NULL | | 29 | 16 | 567 | 619 | | 28 | 16 | NULL | NULL | | 28 | 16 | 595 | 567 | | 27 | 16 | NULL | NULL | | 27 | 16 | 627 | 621 | | 26 | 16 | NULL | NULL | | 26 | 16 | 605 | 595 | | 33 | 17 | NULL | NULL | | 33 | 17 | 567 | 619 | | 37 | 19 | NULL | NULL | | 37 | 19 | 52 | 619 | | 36 | 19 | NULL | NULL | | 36 | 19 | 52 | 619 | | 35 | 19 | NULL | NULL | | 35 | 19 | 595 | 619 | | 34 | 19 | NULL | NULL | | 34 | 19 | 63 | 621 | | 38 | 20 | NULL | NULL | | 38 | 20 | 63 | 621 | | 39 | 20 | NULL | NULL | | 39 | 20 | 63 | 621 | | 40 | 21 | NULL | NULL | | 40 | 21 | 605 | 595 | +----+-----------+------+------+ +----+-----------+------+------+

Answer1:

I found that if I set the lft and rght values of the top level item to 1 and 2 respectively, recover() now generates the rest of the values properly. I find this to be a bug, but not a terrible one.

Recommend

  • query dynamodb with BETWEEN ComparisonOperator
  • PHP > Form a multi-dimensional array from a nested set model flat array
  • Convert a flat datastructure into a tree
  • Combine two MYSQL SELECT queries [duplicate]
  • Cakephp 3 - MissingDatasourceConfigException when running phpunit test
  • What are the reordering columns on laravel-backpack?
  • Getting rollback in creating shortcuts on installation of node js in windows 7
  • LDA: Why sampling for inference of a new document?
  • CSS Local Font not showing up
  • writing unicode to binary file in python
  • Bokeh 0.7.1: Dynamically Add Plot to Bokeh-Server Generated Existing Page
  • SEO friendly 301 redirect .htm to .aspx
  • how to translate xml using xslt with complex rules
  • C++ - Is destructor called when a vector holds objects?
  • Why is it still possible to insert a foreign key that doesn't exist?
  • Ant: fileset “dir” attribute with a runtime expanded full path
  • textIndicatorPrecision in dojox.dgauges using dojo
  • What is Closure Compiler?
  • Pointer vs Reference difference when passing Eigen objects as arguments
  • LNK1104: cannot open file 'kernel32.lib'
  • C++ cout and enum representations
  • Problem with Django using Apache2 (mod_wsgi), Occassionally is “unable to import from module” for no
  • Can my PDF ping my server when it is opened?
  • Pycharm: Marking a folder as 'sources root' is not recursive for subfolders
  • CakePHP ACL tutorial initDB function warnings
  • Scrapy recursive link crawler
  • NetLogo BehaviorSpace - Measure runs using reporters
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Javascript Callbacks with Object constructor
  • How to handle AllServersUnavailable Exception
  • Convert array of 8 bytes to signed long in C++
  • Proper folder structure for lots of source files
  • Understanding cpu registers
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • How can I remove ASP.NET Designer.cs files?
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • Is there any way to bind data to data.frame by some index?
  • Recursive/Hierarchical Query Using Postgres
  • Running Map reduces the dimensions of the matrices
  • How can I use `wmic` in a Windows PE script?