Last active
December 17, 2015 01:09
-
-
Save zoghal/5526172 to your computer and use it in GitHub Desktop.
CakePHP - virtual tree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Page extends AppModel{ | |
public $useTable = 'objects'; | |
public $actsAs = array( | |
'Tree' => array( 'recursive' => 0 ) | |
); | |
public $virtualFields = array( | |
'lft' => 'Tree.lft', | |
'rght' => 'Tree.rght', | |
'parent_id' => 'Tree.parent_id', | |
) | |
public $hasOne = array( | |
'Tree' => array( | |
'className' => 'Tree', | |
'foreignKey' => 'object_id', | |
'dependent' => true | |
), | |
); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE `objects` ( | |
`id` int(11) NOT NULL AUTO_INCREMENT, | |
`site_id` int(11) DEFAULT NULL, | |
`type` varchar(255) COLLATE utf8_persian_ci NOT NULL, | |
`model` varchar(255) COLLATE utf8_persian_ci NOT NULL, | |
`lang` varchar(5) COLLATE utf8_persian_ci NOT NULL, | |
`name` varchar(255) COLLATE utf8_persian_ci NOT NULL, | |
`alias` varchar(255) COLLATE utf8_persian_ci NOT NULL, | |
`home` tinyint(1) NOT NULL DEFAULT '0', | |
`status` tinyint(1) NOT NULL DEFAULT '1', | |
`content_count` int(11) DEFAULT '0', | |
`service_count` int(11) DEFAULT '0', | |
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | |
`modifed` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', | |
PRIMARY KEY (`id`), | |
KEY `fk_objects_sites_1` (`site_id`) | |
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 COLLATE=utf8_persian_ci; | |
CREATE TABLE `objects_tree` ( | |
`object_id` int(11) NOT NULL, | |
`parent_id` int(11) DEFAULT NULL, | |
`lft` int(11) NOT NULL, | |
`rght` int(11) DEFAULT NULL, | |
PRIMARY KEY (`object_id`), | |
KEY `fk_objects_sites_1` (`object_id`) | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_persian_ci; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Tree extends AppModel{ | |
public $useTable = 'objects_tree'; | |
public $belongsTo = array( | |
'belongsTo' => array( | |
'className' => 'Page', | |
'foreignKey' => 'object_id', | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment