this should work
function find($type, $queryData = array()) {
if(isset($queryData['index'])) {
if($queryData['index'] === true) {
$index_path =
'{n}.'.$this->alias.'.'.$this->primaryKey;
} elseif(is_string($queryData['index'])) {
$index_path = $queryData['index'];
} else {
return parent::find($type, $queryData);
}
$r = parent::find($type, $queryData);
return Set::combine($r,$index_path,'{n}');
} else {
return parent::find($type, $queryData);
}
}
On Tue, Sep 2, 2008 at 3:00 PM, Marc Schuetze <marcschuetze@gmail.com> wrote:
> I included this
>
> function find($type, $queryData = array()) {
> if(isset($queryData['index'])) {
> if($queryData['index'] === true) {
> $index_path = '{n}.'.$this->alias.'.'.$this->primaryKey;
> } elseif(is_string($queryData['index'])) {
> $index_path = $queryData['index'];
> } else {
> return parent::find($type, $queryData);
> }
> $r = parent::find($type, $queryData);
> return Set::combine($r,$index_path,'{n}.'.$this->alias);
> } else {
> return parent::find($type, $queryData);
> }
> }
>
> in my AppModel now.
> It adds another option to the queryData array so it can be used like this:
>
> $this->Model->find('all',array('index' => true))
>
> I'll have to think of a way so associated data can also be easily indexed.
>
>
> On Tue, Sep 2, 2008 at 11:55 AM, Howard Glynn <hglynn@gmail.com> wrote:
>>
>> The only thing I might add is to write a custom method in your model to do
>> this find and reindexing.
>>
>> At least then, hopefully, when (if) this becomes possible, the refactoring
>> is a heck of a lot easier and should result in code removal with no change
>> to controllers.
>>
>> In fact I've found myself purging all find() calls from controllers in
>> favour of model methods, it makes writing test cases easier against the
>> models and helped in the business of converting to the new find syntax. And
>> occasionally I'm able to optimize where I have to do reindexing (eg expanded
>> use of Set:: class)
>>
>> Like yourself I'm reluctant to put things like this in AppModel., although
>> it would be ok in the model i guess.
>>
>> I do think what you are asking is possible with the Set class with a lot of
>> trial and error (i know i have) but again you'd want to hide that in a model
>> method.
>>
>>
>> On Tue, Sep 2, 2008 at 10:08 AM, Marc Schuetze <marcschuetze@gmail.com>
>> wrote:
>>>
>>> too bad that there is no way to do it.
>>> I'm currently doing it exactly the way you suggested but I was hoping
>>> for an easier solution.
>>> It get's a bit more difficult when you want the associated data to be
>>> indexed.
>>> But especially it is not so nice because it does affect performance
>>>
>>
>>
>> >>
>>
>
--~--~---------~--~----~------------~-------~--~----~
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:
Post a Comment