Thursday, January 29, 2009

Re: Set::combine (or maybe merge and a couple extracts)

Set does quite a bit of looping too, but it also looks much prettier
in the code ;)

That being said I did not find a way to use Set for this scenario, if
you do please share and I'll gladly update the post.

On Jan 29, 2:15 am, brian <bally.z...@gmail.com> wrote:
> That does look nice. While I was trying to avoid looping over the
> resultset, this little nugget might be very handy in AppModel, as you
> suggest. Thanks!
>
> On Thu, Jan 29, 2009 at 2:03 AM, teknoid <teknoid.cake...@gmail.com> wrote:
>
> > Not a one-liner, but perhaps it'll be helpful...
>
> >http://teknoid.wordpress.com/2008/09/29/dealing-with-calculated-field...
>
> > On Jan 29, 1:50 am, brian <bally.z...@gmail.com> wrote:
> >> Paging grigri ... ;-)
>
> >> I have some data that is the result of a stored procedure call that
> >> I'm struggling to re-shape into a more desirable array. One of the
> >> selected columns is the result of a CASE block which checks values
> >> from a couple of tables, returning the appropriate field. As such,
> >> Cake can't give me a model key and puts it under "0" (zero). I'd like
> >> to move the value under that to inside the other array.
>
> >> This appears so simple, yet I've tried--and failed--with all sorts of
> >> Set::extract/merge/combine ... er, combinations. I know I can use
> >> map() but creating a callback seems like overkill for something that
> >> will *never* be used anywhere else in the app. I could do it in a
> >> foreach loop with a tmp array but, well, what's the point of that?
>
> >> Let's have a look:
>
> >> Array
> >> (
> >>     [0] => Array
> >>         (
> >>             [Model] => Array
> >>                 (
> >>                     [id] => 227
> >>                 )
>
> >>             [0] => Array
> >>                 (
> >>                     [foo] => some string    // <- my CASE block field
> >>                 )
>
> >>         )
>
> >>     [1] => Array
> >>         (
> >>             [Model] => Array
> >>                 (
> >>                     [id] => 228
> >>                 )
>
> >>             [0] => Array
> >>                 (
> >>                     [foo] => some other string
> >>                 )
>
> >>         )
> >>         // etc ...
>
> >> I'd like it to be in this form:
>
> >> Array
> >> (
> >>         [0] => Array
> >>         (
> >>                 [Model] => Array
> >>                 (
> >>                     [id] => 227
> >>                     [foo] => some string
> >>                 )
>
> >>         )
>
> >>     [1] => Array
> >>         (
> >>             [Model] => Array
> >>                 (
> >>                     [id] => 228
> >>                     [foo] => some other string
> >>                 )
>
> >> Can anyone point me in the right direction? I'm sure this is a Set
> >> class one-liner.
>
> >> btw, I've grown to love the Set class but have yet to see a clear
> >> explanation of the params that Set::combine takes. I've seen examples
> >> here on the list but have never been able to figure out what makes
> >> them work. I'd really appreciate a clue on that.
>
>
--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: