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-17 Thread b logica

On Fri, Jun 13, 2008 at 8:34 PM, Tim Fisken <[EMAIL PROTECTED]> wrote:
>
> 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']
>

I disagree. I think that would cause much pain. Just imagine trying to
iterate over such a structure. No thanks!

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



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

2008-06-13 Thread francky06l

Check the set::extract, you might find something working for your
needs.. ( have a look in the test cases, they are usually a very good
tutorial :-)

On Jun 13, 11:13 pm, zw <[EMAIL PROTECTED]> wrote:
> Thanks for the tip, I've done that before when finding a single
> object, but that won't work for an array.  I'll just work on writing
> something in the model that loops through the results and returns an
> array without the model name.
>
> On Jun 13, 6:28 am, RichardAtHome <[EMAIL PROTECTED]> wrote:
>
> > If you don't like it (and you have no othermodelassociations as
> > mentioned by AD7) you can change it in the controller:
>
> > $post = $this->Post->find();
> > $post = $post['Post'];
>
> > On Jun 12, 8:54 pm, AD7six <[EMAIL PROTECTED]> wrote:
>
> > > On Jun 12, 9:44 pm, zw <[EMAIL PROTECTED]> wrote:
>
> > > > I've been using CakePHP for a few projects and really think it's a
> > > > great frameworks except one thing. I can't get my head around why all
> > > > results have themodelname in the associativearray. I don't see any
> > > > benefit of doing this. If you're trying to get a Post object and you
> > > > do: $post = $this->Post->find()
>
> > > It'sredundantonly if you have nomodelassociations unless you want
> > > to risk for example, Post.comment being impossible to access.
>
> > > For 
> > > info.http://groups.google.com/group/cake-php/browse_thread/thread/e86a35ad...
--~--~-~--~~~---~--~~
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-13 Thread zw

Thanks for the tip, I've done that before when finding a single
object, but that won't work for an array.  I'll just work on writing
something in the model that loops through the results and returns an
array without the model name.

On Jun 13, 6:28 am, RichardAtHome <[EMAIL PROTECTED]> wrote:
> If you don't like it (and you have no othermodelassociations as
> mentioned by AD7) you can change it in the controller:
>
> $post = $this->Post->find();
> $post = $post['Post'];
>
> On Jun 12, 8:54 pm, AD7six <[EMAIL PROTECTED]> wrote:
>
> > On Jun 12, 9:44 pm, zw <[EMAIL PROTECTED]> wrote:
>
> > > I've been using CakePHP for a few projects and really think it's a
> > > great frameworks except one thing. I can't get my head around why all
> > > results have themodelname in the associativearray. I don't see any
> > > benefit of doing this. If you're trying to get a Post object and you
> > > do: $post = $this->Post->find()
>
> > It'sredundantonly if you have nomodelassociations unless you want
> > to risk for example, Post.comment being impossible to access.
>
> > For 
> > info.http://groups.google.com/group/cake-php/browse_thread/thread/e86a35ad...

--~--~-~--~~~---~--~~
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-13 Thread RichardAtHome

If you don't like it (and you have no other model associations as
mentioned by AD7) you can change it in the controller:

$post = $this->Post->find();
$post = $post['Post'];


On Jun 12, 8:54 pm, AD7six <[EMAIL PROTECTED]> wrote:
> On Jun 12, 9:44 pm, zw <[EMAIL PROTECTED]> wrote:
>
> > I've been using CakePHP for a few projects and really think it's a
> > great frameworks except one thing. I can't get my head around why all
> > results have the model name in the associative array. I don't see any
> > benefit of doing this. If you're trying to get a Post object and you
> > do: $post = $this->Post->find()
>
> It's redundant only if you have no model associations unless you want
> to risk for example, Post.comment being impossible to access.
>
> For 
> info.http://groups.google.com/group/cake-php/browse_thread/thread/e86a35ad...
--~--~-~--~~~---~--~~
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-12 Thread AD7six



On Jun 12, 9:44 pm, zw <[EMAIL PROTECTED]> wrote:
> I've been using CakePHP for a few projects and really think it's a
> great frameworks except one thing. I can't get my head around why all
> results have the model name in the associative array. I don't see any
> benefit of doing this. If you're trying to get a Post object and you
> do: $post = $this->Post->find()

It's redundant only if you have no model associations unless you want
to risk for example, Post.comment being impossible to access.

For info.
http://groups.google.com/group/cake-php/browse_thread/thread/e86a35ada7ba7ce3/6ae24de237098abd

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



How to perform find without redundant model name in results array

2008-06-12 Thread zw

I've been using CakePHP for a few projects and really think it's a
great frameworks except one thing. I can't get my head around why all
results have the model name in the associative array. I don't see any
benefit of doing this. If you're trying to get a Post object and you
do: $post = $this->Post->find()

why should you have to access the variables like: $post['Post']
['title'] instead of $post['title']

It's overly verbose and redundant, and adds no benefit. It makes a
little more sense in a hasMany association but even then, I don't
think it's optimal. If you have a Post that has many Comments. It
seems more logical to me to have the following structure: $post =
$this->Post->find()

$post => array('title' => 'post title', 'author' => 'john doe',
'comments' => array(0 => array('body' => '...a comment..')))

where the comments array is used like an instance variable of the Post
object.

I'm curious if there is a way to implement this, possibly using
afterFind to modify the results in AppModel? I'm also wondering why it
was implemented like this and there is some benefit or use case I'm
not seeing.

Thanks,
zw

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---