Hi,

John Andersen wrote:
> I do think that if you don't like something in CakePHP, please write
> your own solution to it, then offer it to the CakePHP developers.

Sure. I'd like to understand first, though :-)

In CakePHP, Parent -> Node -> Child leads to different ways to handle a
single Node:

$node['id'];    // in case Node has been retrieved by Parent
$node[Child'];

but

$currentRecord['Node']['id']; // Node has been retrieved by Node
$currentRecord['Child'];

This seems to add complexity.



Now, here is what I would aim for (including the Ghost you added)

Array
(
    [Parent] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [Node] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 17
                                    [Child] => Array
                                        (
                                        )
                                )
                            [1] => Array
                                (
                                    [id] => 19
                                    [Child] => Array
                                        (
                                        )
                                )
                        )
                    [Ghost] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 2
                                )
                            [1] => Array
                                (
                                    [id] => 3
                                )
                        )
                )
        )
)

This way I can say

$resultSet             <- This is an array of Parents
$currentRecord = $resultSet['Parent']['0']
$currentRecord         <- This is a Parent
$currentRecord['id']
$currentRecord['Node']
$currentRecord['Node'][0]['id']
$currentRecord['Node'][0]['Child']
$currentRecord['Ghost]

In the original CakePHP structure,

$resultSet  <- This is an array of arrays(Parent,Nodes, Ghosts)
$currentRecord = $resultSet['0']
$currentRecord        <- This is a Parent/Nodes/Ghosts array
$currentRecord['Parent']
$currentRecord['Parent']['id']
$currentRecord['Node']
$currentRecord['Node'][0]['Child]
$currentRecord['Ghost']

So basically, my way, you need to write *less* to access members of
'Parent'. The rest is pretty similar. But, (huge benefit, I think), you
can handle a Node always in the same way, regardless of whether you get
it included in a Parent or use the Node Model directly:

My way:

$node['id'];  // no matter what
$node['Child'];

Remeber the CakePHP way:

$node['id'];    // in case Node has been retrieved by Parent
$node[Child'];

but

$currentRecord['Node']['id']; // Node has been retrieved by Node
$currentRecord['Child'];


> Does the above helps you to clarify why the original structure is
> good?

Not yet, I am afraid. Maybe I was able to intrigue you with my proposal? :-)

Regards,

Roland


> Enjoy,
>    John
> 
> 
> 
> On May 7, 10:05 am, Roland Bock <feedback2...@eudoxos.de> wrote:
>> Hi,
>>
>> sorry to bring this up again, but I firmly believe that model data
>> structure is inconsistent. I really don't get the current logic and
>> haven't found any documentation explaining it.
>>
>> Suppose you have these models:
>>
>> class Parent extends AppModel
>> {
>>    var $hasMany = array('Node');}
>>
>> class Node extends AppModel
>> {
>>    var $hasMany = array('Child');
>>
>> }
>>
>> Then Parent->find yields something like:
>>
>> Array
>> (
>>     [0] => Array
>>         (
>>             [Parent] => Array
>>                 (
>>                     [id] => 7
>>                 )
>>
>>             [Node] => Array
>>                 (
>>                     [0] => Array
>>                         (
>>                             [id] => 159
>>                             [parent_id] => 7
>>                             [Child] => Array
>>                                 (
>> [...]
>>
>> Essentially, the data structure is
>>
>> Parent
>> Node
>>   - Child
>>
>> I would expect it to be
>>
>> Parent
>>    - Node
>>         - Child
>>
>> I'd really like to understand why the data structure is as it is and/or
>> how it can be changed to my expectations.
>>
>> Thanks and regards,
>>
>> Roland
>>
>> Check out the new CakePHP Questions sitehttp://cakeqs.organd help others 
>> with their CakePHP related questions.
>>
>> You received this message because you are subscribed to the Google Groups 
>> "CakePHP" group.
>> To post to this group, send email to cake-php@googlegroups.com
>> To unsubscribe from this group, send email to
>> cake-php+unsubscr...@googlegroups.com For more options, visit this group 
>> athttp://groups.google.com/group/cake-php?hl=en
> 
> Check out the new CakePHP Questions site http://cakeqs.org and help others 
> with their CakePHP related questions.
> 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to