Re: How to perform find without redundant model name in results array

2008-06-17 Thread Tim Fisken



On Jun 17, 9:24 am, "b logica" <[EMAIL PROTECTED]> wrote:
> On Fri, Jun 13, 2008 at 8:34 PM, Tim Fisken <[EMAIL PROTECTED]> wrote:
> > this case. Odd as it might seem, it would be better, and more
> > consistent, if Cake produced an array like this:
>
> > $post['Comment'][0]['Comment']['author']
> > $post['Comment'][0]'Profile']['homepage']
>
> I disagree. I think that would cause much pain. Just imagine trying to
> iterate over such a structure. No thanks!

It would be _easier_ to iterate over a structure like this than the
current structure, because it's more consistent. If you had a function
like:

function print_comment($comment)
{
  // Print out the comment
}

You could do something like:

$comments = $this->Comment->findAll();
foreach($comments as $comment)
{
print_comment($comment);
}

Or you could do:

$post = $this->Post->read(null, $id);
foreach($post['Comment'] as $comment)
{
print_comment($comment);
}

Right now, the format of the data is different in the two cases, so
you can't use the same print_comment function in both contexts, which
is, frankly, broken.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to perform find without redundant model name in results array

2008-06-14 Thread Tim Fisken

On Jun 12, 12:54 pm, AD7six <[EMAIL PROTECTED]> wrote:
> It's redundant only if you have no model associations unless you want
> to risk for example, Post.comment being impossible to access.

But shouldn't this logic also apply to associated models. Currently,
if you have a post and its comments, you would do:

$post['Comment'][0]['author']

To get the author field of the comment; but you would do

$post['Comment'][0]['Profile']['homepage']

to get the field 'homepage' from the recursively fetched model
'Profile'; that is, fields and associated models are mixed together in
this case. Odd as it might seem, it would be better, and more
consistent, if Cake produced an array like this:

$post['Comment'][0]['Comment']['author']
$post['Comment'][0]'Profile']['homepage']

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---