Re: Self Joining Model

2006-06-15 Thread DJ Spark

after setting $galleries in my view with 'findAllThreaded()


  link($row['Gallery']['title'],'/galleries/edit/' .
$row['Gallery']['id'])?>
   _root 




  link($subGal['Gallery']['title'],'/galleries/edit/' .
$subGal['Gallery']['id'])?>





 Since I have only one level, it's all I need.
 Any suggestions from the hardcore coders, to make a n-level loop ?

 Spark


On 6/15/06, Olivier Percebois-Garve <[EMAIL PROTECTED]> wrote:
>
>  How do you use the array returned by $this->Model->findAllThreaded() ?
>
>
>  DJ Spark wrote:
>  I use this in my Gallery Model:
>
> var $hasMany = array(
>  'Galleries' => array(
>  'className' => 'Gallery',
>  'order' => 'Galleries.ord ASC',
>  'foreignKey' => 'parent_id'));
> var $belongsTo = array(
>  'Galleries' => array(
>  'className' => 'Gallery',
>  'order' => 'Galleries.ord ASC',
>  'foreignKey' => 'parent_id'));
>
> First, note the 'Galleries' (you change that association name for any
> other, just dont use the model name). Second, you might want to know
> more about $this->Model->findAllThreaded() . It returns a *VERY*
> useful array , with ['child'] and everything. I *heart* CakePHP :)
>
>  spakr
>
>
> On 6/15/06, I. E. Smith-Heisters <[EMAIL PROTECTED]> wrote:
>
>
>  Hi all,
>
> I've found a few threads on related subjects, but none of them offer a
> solution:
>
> http://groups.google.com/group/cake-php/browse_thread/thread/8ad0ebbb9171b5a4/82f28d0b433191be?q=finderSQL&rnum=7#82f28d0b433191be
> http://groups.google.com/group/cake-php/browse_thread/thread/ed9f11b62fd2d223/c46ddbf9860e0be6?q=finderSQL&rnum=3#c46ddbf9860e0be6
> http://groups.google.com/group/cake-php/browse_frm/thread/aba68ec53a2ae064/9988348a93f13d1e#9988348a93f13d1e
>
> I have a table that looks like this:
>
> +---+--+--+-+-++
> | Field | Type | Null | Key | Default | Extra
> |
> +---+--+--+-+-++
> | id | int(10) unsigned | | PRI | NULL | auto_increment
> |
> | name | varchar(255) | YES | | NULL |
> |
> | ui_name | varchar(50) | | | |
> |
> | parent_id | int(10) unsigned | YES | | NULL |
> |
> +---+--+--+-+-++
>
> which represents nested menus. I would think it would be trivial to
> allow each MenuItem to have children (whose parent_id is equal to its
> id) by using hasMany.
>
> So, first I tried this:
> class MenuItem extends AppModel {
>  var $name = 'MenuItem';
>  var $useTable = 'tester';
>
>  var $validate = array (
>  'name' => VALID_NOT_EMPTY,
>  );
>  var $hasMany = 'MenuItem';
> }
>
> but that just overwrites the main node,
> $this->MenuItem->read():
> array(1) {
>  ["MenuItem"]=>
>  array(0) {
>  }
> }
>
> so I tried something like this instead:
>
>  var $hasMany = array (
>  'child' => array (
>  'className' => 'MenuItem',
>  )
>  );
>
> which at least doesn't overwrite the main object, but still doesn't
> populate the child array:
> array(2) {
>  ["MenuItem"]=>
>  array(4) {
>  ["id"]=>
>  string(1) "4"
>  ["name"]=>
>  string(9) "community"
>  ["ui_name"]=>
>  string(9) "Community"
>  ["parent_id"]=>
>  NULL
>  }
>  ["child"]=>
>  array(0) {
>  }
> }
> So then I tried a finderSQL parameter
>
>  var $hasMany = array (
>  'child' => array (
>  'className' => 'MenuItem',
>  'finderSQL' => 'SELECT * FROM tester AS one LEFT JOIN tester AS two
> ON one.id = two.parent_id'
>  )
>  );
>
> but that has the same output on read() as the attempt with finderSQL
> undefined. Unfortunately, I haven't found a single successful example
> of using finderSQL, so it's hard to tell what sort of output the SQL
> statement should have. I just grabbed and modded this statement from
> one of the other threads I mentioned.
>
> Okay, so then there's findAllThreaded and guiListTree. The former seems
> to work (albeit it's kind of uncontrollable), but I really think this
> part of the model belongs in the model definition.. The latter,
> guiListTree doesn't seem to work as expected and is marked as
> deprecated in the documentation..
>
> So, does anyone have any suggestions for building a tree out of a
> self-joining table?
>
> Thanks much,
> Ian Smith-Heisters
>
>
>
>
>
>
>
>  >
>
>


-- 
[web] http://synapsisdi.com.br
[livesets] http://djspark.com.br

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Self Joining Model

2006-06-15 Thread Olivier Percebois-Garve




Thanks Felix I wanted to make that sure.
Everyone its way... I don't see the benefit of findAllThreaded(). It
results in having two recursion, one made by cake, the second in the
app.
Recursion is very heavy for php, and crawling a tree 2 times seems to
me unnecessary.
I'm curious to see if the 'actAs' thing could bring us a better way to
handle this.

Felix Geisendörfer wrote:

  
  
You have to write a recursive function when working with arrays from
findAllThreaded().
  
You basically loop through all the items and check if they have an
array called 'Children' (or sth like that). If so, you make the
function call itself with the children array as a parameter, if not,
you put in your code to display/modify/do stuff with the items
themselfs ...
  
  --
  http://www.thinkingphp.org
  http://www.fg-webdesign.de
  
  
  
Olivier Percebois-Garve schrieb:
  

How do you use the array returned by
$this->Model->findAllThreaded() ?

DJ Spark wrote:

  I use this in my Gallery Model:

var $hasMany =  array(
			'Galleries' => array(
'className' => 'Gallery',
'order'		=> 'Galleries.ord ASC',
'foreignKey'   => 'parent_id'));
var $belongsTo =  array(
			'Galleries' => array(
'className' => 'Gallery',
'order'		=> 'Galleries.ord ASC',
'foreignKey'   => 'parent_id'));

First, note the 'Galleries' (you change that association name for any
other, just dont use  the model name). Second, you might want to know
more about $this->Model->findAllThreaded() . It returns a *VERY*
useful array , with ['child'] and everything. I *heart* CakePHP :)

 spakr


On 6/15/06, I. E. Smith-Heisters <[EMAIL PROTECTED]> wrote:
  
  
Hi all,

I've found a few threads on related subjects, but none of them offer a
solution:

http://groups.google.com/group/cake-php/browse_thread/thread/8ad0ebbb9171b5a4/82f28d0b433191be?q=finderSQL&rnum=7#82f28d0b433191be
http://groups.google.com/group/cake-php/browse_thread/thread/ed9f11b62fd2d223/c46ddbf9860e0be6?q=finderSQL&rnum=3#c46ddbf9860e0be6
http://groups.google.com/group/cake-php/browse_frm/thread/aba68ec53a2ae064/9988348a93f13d1e#9988348a93f13d1e

I have a table that looks like this:

+---+--+--+-+-++
| Field | Type | Null | Key | Default | Extra
|
+---+--+--+-+-++
| id| int(10) unsigned |  | PRI | NULL| auto_increment
|
| name  | varchar(255) | YES  | | NULL|
|
| ui_name   | varchar(50)  |  | | |
|
| parent_id | int(10) unsigned | YES  | | NULL|
|
+---+--+--+-+-++

which represents nested menus. I would think it would be trivial to
allow each MenuItem to have children (whose parent_id is equal to its
id) by using hasMany.

So, first I tried this:
class MenuItem extends AppModel {
var $name = 'MenuItem';
var $useTable = 'tester';

var $validate = array (
'name' => VALID_NOT_EMPTY,
);
var $hasMany = 'MenuItem';
}

but that just overwrites the main node,
$this->MenuItem->read():
array(1) {
  ["MenuItem"]=>
  array(0) {
  }
}

so I tried something like this instead:

var $hasMany = array (
'child' => array (
'className' => 'MenuItem',
)
);

which at least doesn't overwrite the main object, but still doesn't
populate the child array:
array(2) {
  ["MenuItem"]=>
  array(4) {
["id"]=>
string(1) "4"
["name"]=>
string(9) "community"
["ui_name"]=>
string(9) "Community"
["parent_id"]=>
NULL
  }
  ["child"]=>
  array(0) {
  }
}
So then I tried a finderSQL parameter

var $hasMany = array (
'child' => array (
'className' => 'MenuItem',
'finderSQL' => 'SELECT * FROM tester AS one LEFT JOIN tester AS two
ON one.id = two.parent_id'
)
);

but that has the same output on read() as the attempt with finderSQL
undefined. Unfortunately, I haven't found a single successful example
of using finderSQL, so it's hard to tell what sort of output the SQL
statement should have. I just grabbed and modded this statement from
one of the other threads I mentioned.

Okay, so then there's findAllThreaded and guiListTree. The former seems
to work (albeit it's kind of uncontrollable), but I really think this
part of the model belongs in the model definition.. The latter,
guiListTree doesn't seem to work as expected and is marked as
deprecated in the documentation..

So, does anyone have any suggestions for building a tree out of a
self-joining table?

Thanks much,
Ian Smith-Heisters



  
  

  




  
  
  



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake PH

Re: Self Joining Model

2006-06-15 Thread Felix Geisendörfer




You have to write a recursive function when working with arrays from
findAllThreaded().

You basically loop through all the items and check if they have an
array called 'Children' (or sth like that). If so, you make the
function call itself with the children array as a parameter, if not,
you put in your code to display/modify/do stuff with the items
themselfs ...

--
http://www.thinkingphp.org
http://www.fg-webdesign.de



Olivier Percebois-Garve schrieb:

  
How do you use the array returned by
$this->Model->findAllThreaded() ?
  
DJ Spark wrote:
  
I use this in my Gallery Model:

var $hasMany =  array(
			'Galleries' => array(
'className' => 'Gallery',
'order'		=> 'Galleries.ord ASC',
'foreignKey'   => 'parent_id'));
var $belongsTo =  array(
			'Galleries' => array(
'className' => 'Gallery',
'order'		=> 'Galleries.ord ASC',
'foreignKey'   => 'parent_id'));

First, note the 'Galleries' (you change that association name for any
other, just dont use  the model name). Second, you might want to know
more about $this->Model->findAllThreaded() . It returns a *VERY*
useful array , with ['child'] and everything. I *heart* CakePHP :)

 spakr


On 6/15/06, I. E. Smith-Heisters <[EMAIL PROTECTED]> wrote:
  

  Hi all,

I've found a few threads on related subjects, but none of them offer a
solution:

http://groups.google.com/group/cake-php/browse_thread/thread/8ad0ebbb9171b5a4/82f28d0b433191be?q=finderSQL&rnum=7#82f28d0b433191be
http://groups.google.com/group/cake-php/browse_thread/thread/ed9f11b62fd2d223/c46ddbf9860e0be6?q=finderSQL&rnum=3#c46ddbf9860e0be6
http://groups.google.com/group/cake-php/browse_frm/thread/aba68ec53a2ae064/9988348a93f13d1e#9988348a93f13d1e

I have a table that looks like this:

+---+--+--+-+-++
| Field | Type | Null | Key | Default | Extra
|
+---+--+--+-+-++
| id| int(10) unsigned |  | PRI | NULL| auto_increment
|
| name  | varchar(255) | YES  | | NULL|
|
| ui_name   | varchar(50)  |  | | |
|
| parent_id | int(10) unsigned | YES  | | NULL|
|
+---+--+--+-+-++

which represents nested menus. I would think it would be trivial to
allow each MenuItem to have children (whose parent_id is equal to its
id) by using hasMany.

So, first I tried this:
class MenuItem extends AppModel {
var $name = 'MenuItem';
var $useTable = 'tester';

var $validate = array (
'name' => VALID_NOT_EMPTY,
);
var $hasMany = 'MenuItem';
}

but that just overwrites the main node,
$this->MenuItem->read():
array(1) {
  ["MenuItem"]=>
  array(0) {
  }
}

so I tried something like this instead:

var $hasMany = array (
'child' => array (
'className' => 'MenuItem',
)
);

which at least doesn't overwrite the main object, but still doesn't
populate the child array:
array(2) {
  ["MenuItem"]=>
  array(4) {
["id"]=>
string(1) "4"
["name"]=>
string(9) "community"
["ui_name"]=>
string(9) "Community"
["parent_id"]=>
NULL
  }
  ["child"]=>
  array(0) {
  }
}
So then I tried a finderSQL parameter

var $hasMany = array (
'child' => array (
'className' => 'MenuItem',
'finderSQL' => 'SELECT * FROM tester AS one LEFT JOIN tester AS two
ON one.id = two.parent_id'
)
);

but that has the same output on read() as the attempt with finderSQL
undefined. Unfortunately, I haven't found a single successful example
of using finderSQL, so it's hard to tell what sort of output the SQL
statement should have. I just grabbed and modded this statement from
one of the other threads I mentioned.

Okay, so then there's findAllThreaded and guiListTree. The former seems
to work (albeit it's kind of uncontrollable), but I really think this
part of the model belongs in the model definition.. The latter,
guiListTree doesn't seem to work as expected and is marked as
deprecated in the documentation..

So, does anyone have any suggestions for building a tree out of a
self-joining table?

Thanks much,
Ian Smith-Heisters






  
  
  
  
  


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.  To post to this group, send email to cake-php@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/cake-php  -~--~~~~--~~--~--~---





Re: Self Joining Model

2006-06-15 Thread I. E. Smith-Heisters

I haven't had much success/use for/with it. I would guess write a
custom loop, or modify guiTreeList() as described here:

http://groups.google.com/group/cake-php/browse_thread/thread/2ad5bc9ec2f5158c/60198efd89f6e095?q=findAllThreaded+guiListTree&rnum=2#60198efd89f6e095

But I've been using Cake for less than a day, so someone else should
know better than me.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Self Joining Model

2006-06-15 Thread Olivier Percebois-Garve




How do you use the array returned by
$this->Model->findAllThreaded() ?

DJ Spark wrote:

  I use this in my Gallery Model:

var $hasMany =  array(
			'Galleries' => array(
'className' => 'Gallery',
'order'		=> 'Galleries.ord ASC',
'foreignKey'   => 'parent_id'));
var $belongsTo =  array(
			'Galleries' => array(
'className' => 'Gallery',
'order'		=> 'Galleries.ord ASC',
'foreignKey'   => 'parent_id'));

First, note the 'Galleries' (you change that association name for any
other, just dont use  the model name). Second, you might want to know
more about $this->Model->findAllThreaded() . It returns a *VERY*
useful array , with ['child'] and everything. I *heart* CakePHP :)

 spakr


On 6/15/06, I. E. Smith-Heisters <[EMAIL PROTECTED]> wrote:
  
  
Hi all,

I've found a few threads on related subjects, but none of them offer a
solution:

http://groups.google.com/group/cake-php/browse_thread/thread/8ad0ebbb9171b5a4/82f28d0b433191be?q=finderSQL&rnum=7#82f28d0b433191be
http://groups.google.com/group/cake-php/browse_thread/thread/ed9f11b62fd2d223/c46ddbf9860e0be6?q=finderSQL&rnum=3#c46ddbf9860e0be6
http://groups.google.com/group/cake-php/browse_frm/thread/aba68ec53a2ae064/9988348a93f13d1e#9988348a93f13d1e

I have a table that looks like this:

+---+--+--+-+-++
| Field | Type | Null | Key | Default | Extra
|
+---+--+--+-+-++
| id| int(10) unsigned |  | PRI | NULL| auto_increment
|
| name  | varchar(255) | YES  | | NULL|
|
| ui_name   | varchar(50)  |  | | |
|
| parent_id | int(10) unsigned | YES  | | NULL|
|
+---+--+--+-+-++

which represents nested menus. I would think it would be trivial to
allow each MenuItem to have children (whose parent_id is equal to its
id) by using hasMany.

So, first I tried this:
class MenuItem extends AppModel {
var $name = 'MenuItem';
var $useTable = 'tester';

var $validate = array (
'name' => VALID_NOT_EMPTY,
);
var $hasMany = 'MenuItem';
}

but that just overwrites the main node,
$this->MenuItem->read():
array(1) {
  ["MenuItem"]=>
  array(0) {
  }
}

so I tried something like this instead:

var $hasMany = array (
'child' => array (
'className' => 'MenuItem',
)
);

which at least doesn't overwrite the main object, but still doesn't
populate the child array:
array(2) {
  ["MenuItem"]=>
  array(4) {
["id"]=>
string(1) "4"
["name"]=>
string(9) "community"
["ui_name"]=>
string(9) "Community"
["parent_id"]=>
NULL
  }
  ["child"]=>
  array(0) {
  }
}
So then I tried a finderSQL parameter

var $hasMany = array (
'child' => array (
'className' => 'MenuItem',
'finderSQL' => 'SELECT * FROM tester AS one LEFT JOIN tester AS two
ON one.id = two.parent_id'
)
);

but that has the same output on read() as the attempt with finderSQL
undefined. Unfortunately, I haven't found a single successful example
of using finderSQL, so it's hard to tell what sort of output the SQL
statement should have. I just grabbed and modded this statement from
one of the other threads I mentioned.

Okay, so then there's findAllThreaded and guiListTree. The former seems
to work (albeit it's kind of uncontrollable), but I really think this
part of the model belongs in the model definition.. The latter,
guiListTree doesn't seem to work as expected and is marked as
deprecated in the documentation..

So, does anyone have any suggestions for building a tree out of a
self-joining table?

Thanks much,
Ian Smith-Heisters



  
  

  



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.  To post to this group, send email to cake-php@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/cake-php  -~--~~~~--~~--~--~---





Re: Self Joining Model

2006-06-15 Thread Felix Geisendörfer




This is a sweet "hack" indeed! I'll keep it in mind when working with
difficult nested stuff again! I'll support the award idea ; ).

--
http://www.thinkingphp.org
http://www.fg-webdesign.de



DJ Spark schrieb:

  I use this in my Gallery Model:

var $hasMany =  array(
			'Galleries' => array(
'className' => 'Gallery',
'order'		=> 'Galleries.ord ASC',
'foreignKey'   => 'parent_id'));
var $belongsTo =  array(
			'Galleries' => array(
'className' => 'Gallery',
'order'		=> 'Galleries.ord ASC',
'foreignKey'   => 'parent_id'));

First, note the 'Galleries' (you change that association name for any
other, just dont use  the model name). Second, you might want to know
more about $this->Model->findAllThreaded() . It returns a *VERY*
useful array , with ['child'] and everything. I *heart* CakePHP :)

 spakr


On 6/15/06, I. E. Smith-Heisters <[EMAIL PROTECTED]> wrote:
  
  
Hi all,

I've found a few threads on related subjects, but none of them offer a
solution:

http://groups.google.com/group/cake-php/browse_thread/thread/8ad0ebbb9171b5a4/82f28d0b433191be?q=finderSQL&rnum=7#82f28d0b433191be
http://groups.google.com/group/cake-php/browse_thread/thread/ed9f11b62fd2d223/c46ddbf9860e0be6?q=finderSQL&rnum=3#c46ddbf9860e0be6
http://groups.google.com/group/cake-php/browse_frm/thread/aba68ec53a2ae064/9988348a93f13d1e#9988348a93f13d1e

I have a table that looks like this:

+---+--+--+-+-++
| Field | Type | Null | Key | Default | Extra
|
+---+--+--+-+-++
| id| int(10) unsigned |  | PRI | NULL| auto_increment
|
| name  | varchar(255) | YES  | | NULL|
|
| ui_name   | varchar(50)  |  | | |
|
| parent_id | int(10) unsigned | YES  | | NULL|
|
+---+--+--+-+-++

which represents nested menus. I would think it would be trivial to
allow each MenuItem to have children (whose parent_id is equal to its
id) by using hasMany.

So, first I tried this:
class MenuItem extends AppModel {
var $name = 'MenuItem';
var $useTable = 'tester';

var $validate = array (
'name' => VALID_NOT_EMPTY,
);
var $hasMany = 'MenuItem';
}

but that just overwrites the main node,
$this->MenuItem->read():
array(1) {
  ["MenuItem"]=>
  array(0) {
  }
}

so I tried something like this instead:

var $hasMany = array (
'child' => array (
'className' => 'MenuItem',
)
);

which at least doesn't overwrite the main object, but still doesn't
populate the child array:
array(2) {
  ["MenuItem"]=>
  array(4) {
["id"]=>
string(1) "4"
["name"]=>
string(9) "community"
["ui_name"]=>
string(9) "Community"
["parent_id"]=>
NULL
  }
  ["child"]=>
  array(0) {
  }
}
So then I tried a finderSQL parameter

var $hasMany = array (
'child' => array (
'className' => 'MenuItem',
'finderSQL' => 'SELECT * FROM tester AS one LEFT JOIN tester AS two
ON one.id = two.parent_id'
)
);

but that has the same output on read() as the attempt with finderSQL
undefined. Unfortunately, I haven't found a single successful example
of using finderSQL, so it's hard to tell what sort of output the SQL
statement should have. I just grabbed and modded this statement from
one of the other threads I mentioned.

Okay, so then there's findAllThreaded and guiListTree. The former seems
to work (albeit it's kind of uncontrollable), but I really think this
part of the model belongs in the model definition.. The latter,
guiListTree doesn't seem to work as expected and is marked as
deprecated in the documentation..

So, does anyone have any suggestions for building a tree out of a
self-joining table?

Thanks much,
Ian Smith-Heisters



  
  

  


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.  To post to this group, send email to cake-php@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/cake-php  -~--~~~~--~~--~--~---





Re: Self Joining Model

2006-06-15 Thread I. E. Smith-Heisters

Wow. That was simple. If I had an award to give, I'd give it to you.

Thanks, so much.
-ian


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Self Joining Model

2006-06-15 Thread DJ Spark

I use this in my Gallery Model:

var $hasMany =  array(
'Galleries' => array(
'className' => 'Gallery',
'order' => 'Galleries.ord ASC',
'foreignKey'   => 'parent_id'));
var $belongsTo =  array(
'Galleries' => array(
'className' => 'Gallery',
'order' => 'Galleries.ord ASC',
'foreignKey'   => 'parent_id'));

First, note the 'Galleries' (you change that association name for any
other, just dont use  the model name). Second, you might want to know
more about $this->Model->findAllThreaded() . It returns a *VERY*
useful array , with ['child'] and everything. I *heart* CakePHP :)

 spakr


On 6/15/06, I. E. Smith-Heisters <[EMAIL PROTECTED]> wrote:
>
> Hi all,
>
> I've found a few threads on related subjects, but none of them offer a
> solution:
>
> http://groups.google.com/group/cake-php/browse_thread/thread/8ad0ebbb9171b5a4/82f28d0b433191be?q=finderSQL&rnum=7#82f28d0b433191be
> http://groups.google.com/group/cake-php/browse_thread/thread/ed9f11b62fd2d223/c46ddbf9860e0be6?q=finderSQL&rnum=3#c46ddbf9860e0be6
> http://groups.google.com/group/cake-php/browse_frm/thread/aba68ec53a2ae064/9988348a93f13d1e#9988348a93f13d1e
>
> I have a table that looks like this:
>
> +---+--+--+-+-++
> | Field | Type | Null | Key | Default | Extra
> |
> +---+--+--+-+-++
> | id| int(10) unsigned |  | PRI | NULL| auto_increment
> |
> | name  | varchar(255) | YES  | | NULL|
> |
> | ui_name   | varchar(50)  |  | | |
> |
> | parent_id | int(10) unsigned | YES  | | NULL|
> |
> +---+--+--+-+-++
>
> which represents nested menus. I would think it would be trivial to
> allow each MenuItem to have children (whose parent_id is equal to its
> id) by using hasMany.
>
> So, first I tried this:
> class MenuItem extends AppModel {
> var $name = 'MenuItem';
> var $useTable = 'tester';
>
> var $validate = array (
> 'name' => VALID_NOT_EMPTY,
> );
> var $hasMany = 'MenuItem';
> }
>
> but that just overwrites the main node,
> $this->MenuItem->read():
> array(1) {
>   ["MenuItem"]=>
>   array(0) {
>   }
> }
>
> so I tried something like this instead:
>
> var $hasMany = array (
> 'child' => array (
> 'className' => 'MenuItem',
> )
> );
>
> which at least doesn't overwrite the main object, but still doesn't
> populate the child array:
> array(2) {
>   ["MenuItem"]=>
>   array(4) {
> ["id"]=>
> string(1) "4"
> ["name"]=>
> string(9) "community"
> ["ui_name"]=>
> string(9) "Community"
> ["parent_id"]=>
> NULL
>   }
>   ["child"]=>
>   array(0) {
>   }
> }
> So then I tried a finderSQL parameter
>
> var $hasMany = array (
> 'child' => array (
> 'className' => 'MenuItem',
> 'finderSQL' => 'SELECT * FROM tester AS one LEFT JOIN 
> tester AS two
> ON one.id = two.parent_id'
> )
> );
>
> but that has the same output on read() as the attempt with finderSQL
> undefined. Unfortunately, I haven't found a single successful example
> of using finderSQL, so it's hard to tell what sort of output the SQL
> statement should have. I just grabbed and modded this statement from
> one of the other threads I mentioned.
>
> Okay, so then there's findAllThreaded and guiListTree. The former seems
> to work (albeit it's kind of uncontrollable), but I really think this
> part of the model belongs in the model definition.. The latter,
> guiListTree doesn't seem to work as expected and is marked as
> deprecated in the documentation..
>
> So, does anyone have any suggestions for building a tree out of a
> self-joining table?
>
> Thanks much,
> Ian Smith-Heisters
>
>
> >
>


-- 
[web] http://synapsisdi.com.br
[livesets] http://djspark.com.br

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Self Joining Model

2006-06-15 Thread I. E. Smith-Heisters

Hi all,

I've found a few threads on related subjects, but none of them offer a
solution:

http://groups.google.com/group/cake-php/browse_thread/thread/8ad0ebbb9171b5a4/82f28d0b433191be?q=finderSQL&rnum=7#82f28d0b433191be
http://groups.google.com/group/cake-php/browse_thread/thread/ed9f11b62fd2d223/c46ddbf9860e0be6?q=finderSQL&rnum=3#c46ddbf9860e0be6
http://groups.google.com/group/cake-php/browse_frm/thread/aba68ec53a2ae064/9988348a93f13d1e#9988348a93f13d1e

I have a table that looks like this:

+---+--+--+-+-++
| Field | Type | Null | Key | Default | Extra
|
+---+--+--+-+-++
| id| int(10) unsigned |  | PRI | NULL| auto_increment
|
| name  | varchar(255) | YES  | | NULL|
|
| ui_name   | varchar(50)  |  | | |
|
| parent_id | int(10) unsigned | YES  | | NULL|
|
+---+--+--+-+-++

which represents nested menus. I would think it would be trivial to
allow each MenuItem to have children (whose parent_id is equal to its
id) by using hasMany.

So, first I tried this:
class MenuItem extends AppModel {
var $name = 'MenuItem';
var $useTable = 'tester';

var $validate = array (
'name' => VALID_NOT_EMPTY,
);
var $hasMany = 'MenuItem';
}

but that just overwrites the main node,
$this->MenuItem->read():
array(1) {
  ["MenuItem"]=>
  array(0) {
  }
}

so I tried something like this instead:

var $hasMany = array (
'child' => array (
'className' => 'MenuItem',
)
);

which at least doesn't overwrite the main object, but still doesn't
populate the child array:
array(2) {
  ["MenuItem"]=>
  array(4) {
["id"]=>
string(1) "4"
["name"]=>
string(9) "community"
["ui_name"]=>
string(9) "Community"
["parent_id"]=>
NULL
  }
  ["child"]=>
  array(0) {
  }
}
So then I tried a finderSQL parameter

var $hasMany = array (
'child' => array (
'className' => 'MenuItem',
'finderSQL' => 'SELECT * FROM tester AS one LEFT JOIN 
tester AS two
ON one.id = two.parent_id'
)
);

but that has the same output on read() as the attempt with finderSQL
undefined. Unfortunately, I haven't found a single successful example
of using finderSQL, so it's hard to tell what sort of output the SQL
statement should have. I just grabbed and modded this statement from
one of the other threads I mentioned.

Okay, so then there's findAllThreaded and guiListTree. The former seems
to work (albeit it's kind of uncontrollable), but I really think this
part of the model belongs in the model definition.. The latter,
guiListTree doesn't seem to work as expected and is marked as
deprecated in the documentation..

So, does anyone have any suggestions for building a tree out of a
self-joining table?

Thanks much,
Ian Smith-Heisters


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---