Appreciate the comment. The limit 1 was just there while I was testing
the stuff, it went away soon after I found out the correct syntax.

Thanks for the help,

Alfredo


On Mon, Feb 9, 2009 at 1:22 PM, BrendonKoz <[email protected]> wrote:
>
> As an aside, you can also use the find('first' ...) method rather than
> find('all', ...) like you did, since you limit the result to one in
> your query anyway.  Not much different, they both achieve the same
> thing, but it may be more readable in the code itself.
>
>
> On Feb 8, 5:06 pm, Alfredo Quiroga-Villamil <[email protected]> wrote:
>> I really appreciate it guys, for some reason I didn't try this:
>>
>> Set::extract($aDestinationSummary, '{n}.0');
>>
>> That extracts exactly the set I want, I knew there had to be a simple,
>> clean way to get it but didn't try that for some reason.
>>
>> Thanks so much for the help.
>>
>> Alfredo
>>
>>
>>
>> On Sun, Feb 8, 2009 at 2:32 PM, brian <[email protected]> wrote:
>>
>> > On Sun, Feb 8, 2009 at 10:47 AM, Alfredo Quiroga-Villamil
>> > <[email protected]> wrote:
>>
>> >> I have the following query:
>>
>> >> ===============================================
>> >>            $aParams = array(
>> >>                'fields' => array(
>> >>                    "ifnull(CcCall.destination, 'Total')    as destination"
>> >>                    ,'sec_to_time(sum(CcCall.sessiontime))  as duration'
>> >>                    ,'truncate(sum(CcCall.sessionbill), 2)  as charged'
>> >>                )
>> >>                ,'conditions' => $aConditions
>> >>                ,'group' => 'CcCall.destination with rollup'
>> >>                ,'limit' => 1
>> >>            );
>>
>> >> $aDestinationSummary = $this->CcCall->find('all', $aParams);
>> >> ===============================================
>>
>> >> which returns data as follows:
>>
>> >> ===============================================
>> >> 2009-02-07 23:52:19 Debug: Array
>> >> (
>> >>    [0] => Array
>> >>        (
>> >>            [0] => Array
>> >>                (
>> >>                    [destination] => algeria cellular algerie telecom
>> >>                    [duration] => 00:01:30
>> >>                    [charged] => 0.51
>> >>                )
>>
>> >>        )
>>
>> >> )
>> >> ===============================================
>>
>> >> Typically I would use Set::extract to extract the data I want and
>> >> format it to json to be rendered by the view. However, in this
>> >> particular case, the data is returned in such a way that doesn't at
>> >> least at first glance allow me to use Set::extract.
>>
>> >> Questions:
>>
>> >> 1- Is there a way to format the query above in such a way that returns
>> >> the Model Name as the sub-index for the arrays, hence allowing me to
>> >> use Set::extract?
>>
>> > Cake can't know the model name here because of the use of DB
>> > functions, hence the 2nd 0 key. The first key is the results index,
>> > and so corresponds to Set's '{n}'. The 2nd key will always be 0. So,
>> > for example, to extract destination you just need to do:
>>
>> > Set::extract($results, '{n}.0.destination');
>>
>> >> 2- If 1 is not possible or even if it is, Do we hae a way to just get
>> >> the elements containing data from the array. For instance, something
>> >> like the following:
>>
>> >> $aDestSummary = Set::extract($aDestinationSummary, '{n}');
>>
>> > I'm not sure what you mean by that, based on the example result you
>> > posted. Perhaps you want an inner join?- Hide quoted text -
>>
>> - Show quoted text -
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to