this is what i have been looking for...
but there is a small problem... i am using it on a model which is
belongs to another model.
with a normal find('all') i get this result..
[0] => Array
(
[Model1] => Array
(
[a] => 0
[b] => 1
[id] => 12
)
[Model2] => Array
(
[d] => 2
)
)
[1] => Array
(
[Model1] => Array
(
[a] => 0
[b] => 1
[id] => 6
)
[Model2] => Array
(
[d] => 10
)
)
but after using your index function the result is
[12] => Array
(
[a] => 0
[b] => 1
[id] => 12
)
[6] => Array
(
[a] => 0
[b] => 1
[id] => 6
)
it looses the value of the associated model...
could you help me modify the find function
Thanks in advance
Cheers
Yash
On Sep 2, 2:00 pm, "Marc Schuetze" <marcschue...@gmail.com> wrote:
> I included this
>
> functionfind($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 awayso associated data can also be easily indexed.
>
> On Tue, Sep 2, 2008 at 11:55 AM, Howard Glynn <hgl...@gmail.com> wrote:
>
> > The only thing I might add is to write a custom method in your model to do
> > thisfindand 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 nochange
> > to controllers.
>
> > In fact I've found myself purging allfind() 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 newfindsyntax. 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 <marcschue...@gmail.com>
> > wrote:
>
> >> too bad that there is nowayto do it.
> >> I'm currently doing it exactly thewayyou 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