On Nov 26, 10:38 am, austin <[EMAIL PROTECTED]> wrote:
> new to cake. tried searching for this topic but couldn't find anything
> that addressed my situation.
> -----------------------------
> tables:
> -----------------------------
> CREATE TABLE IF NOT EXISTS `t_machine` (
> `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
> `name` VARCHAR(255),
> `description` text,
> `cost` float(7, 2),
> `status` TINYINT(1) DEFAULT '1',
> `created` TIMESTAMP NULL,
> `modified` TIMESTAMP NULL,
> PRIMARY KEY (`id`)
> ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
> INSERT INTO t_machine('id', 'name') VALUES ('1', 'root');
>
> CREATE TABLE IF NOT EXISTS `t_machine_parts` (
> `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
> `machine_id` INT(11) UNSIGNED,
> `parent_id` INT(11) UNSIGNED,
> `lft` INT(11) UNSIGNED,
> `rght` INT(11) UNSIGNED,
> `part_id` INT(11) UNSIGNED,
> `created` TIMESTAMP NULL,
> `modified` TIMESTAMP NULL,
> PRIMARY KEY (`id`)
> ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
> INSERT INTO t_machine_parts(id, machine_id, parent_id, lft, rght,
> part_id) VALUES
> (1, 1, null, 1, 10, null),
> (2, 1, 1, 2, 9, 1),
> (3, 1, 2, 3, 6, 2),
> (4, 1, 3, 4, 5, 4),
> (5, 1, 2, 7, 8, 3);
>
> CREATE TABLE IF NOT EXISTS `t_parts` (
> `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
> `name` VARCHAR(255),
> `description` text,
> `cost` float(7, 2),
> `boolean` TINYINT(1) DEFAULT '0',
> `status` TINYINT(1) DEFAULT '1',
> `created` TIMESTAMP NULL,
> `modified` TIMESTAMP NULL,
> PRIMARY KEY (`id`)
> ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
> INSERT INTO t_parts(id, name) VALUES
> (1, 'category'),
> (2, 'sub_category_1'),
> (3, 'sub_category_2'),
> (4, 'option of sub_category_1');
> --------------------------------
> models:
> -------------------------------
> Machine
> - hasMany MachinePart joined by machine_id
> MachinePart
> - belongsTo Machine joined by machine_id
> - belongsTo Part joined by part_id
> Part
> - hasMany MachinePart joined by part_id
> --------------------------------
>
> i'm trying to use the tree behavior to give me a hierarchy view of all
> the parts that are used for a given machine. i.e. i pass in a
> machine_id to the MachinePartsController.
>
> here is my relavent MachinePartsController code:
> $machineParts =
> $this->Machine->MachinePart->generatetreelist(array
> ('machine_id' => $id), null, null, '---');
> $this->set('machineParts', $machineParts);
>
> i'm returning an array that looks like this:
> Array
> (
> [1] => 1
> [2] => ---2
> [3] => ------3
> [4] => ---------4
> [5] => ------5
> )
>
> i'm trying to get something that is able to join on the t_parts table
> and will return something like this:
> Array
> (
> [t_machine_part.part_id] => t_part.name
> )
> e.g.:
> Array
> (
> [null] => null
> [1] => ---category
> [2] => ------sub_category_1
> [4] => ---------option of sub_category_1
> [3] => ------sub_category_2
> )
>
> any help would be greatly appreciated.
Look at the params, and change keypath, value path and recursive
https://trac.cakephp.org/browser/branches/1.2.x.x/cake/libs/model/behaviors/tree.php#L295
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---