CakePHP. Behaviors - cheating!
As usual, I’m not looking for easy ways, and as usual I encounter tasks not covered in book.cakephp.org ;-)
Always, the most troublesome part of the project for me was paginate and everything related to it (fetching, sorting).
And now, once again I stepped on a rake, and the answer to my question is no.
So, what the task was:
Model A - hasMany Model B
Model B - belongsTo Model A
Model B - actAs ('Image')
Image - Yevgeny Tomenko’s wonderful behavior , which serves to link the record in the model with the saved picture.
In the case of a query Model B -> ... of any form - behavior worked like a clock, and I received the data I needed, in this case - pictures.
However, when it became a task to build a query of the type
Model B -> Model -> A (with conditions where the sample goes along the Model A fields),
it turned out that the search and pagination work fine, but in the results of the associated Model B there is no trace of behavior ... I just got the model fields, without the “warps” I needed.
No dancing dances with Contain, request order, etc. - did not lead to anything. There is no answer in the google group either.
And today I found another rake, but already with behavior Translate. If you use the instructions , and do as advised there, everything works fine, except for my favorite pegging ...
Namely, you cannot sort by the fields located in the i18n table. Will not work. Only for those fields that are present in explicit form. Like this.
Of course, I do not want to say that sorting a table built through i18n will work quickly, or in principle, will work in a sane manner. Maybe it won’t be. But in this case, if you need to somehow sort the results except id, created, then you have no chance to use this behavior. It will not work. :(
And if the first rake can be bypassed by the second request (first, get the list of id Model B, and then request all records directly from Model B (here the behavior will work). Then in the second rake, the only way to sort is to do without boxed behavior.
2All : If someone solved these issues - share the solution in the comments.This is about CakePHP 1.2.3.8166
Always, the most troublesome part of the project for me was paginate and everything related to it (fetching, sorting).
And now, once again I stepped on a rake, and the answer to my question is no.
So, what the task was:
Model A - hasMany Model B
Model B - belongsTo Model A
Model B - actAs ('Image')
Image - Yevgeny Tomenko’s wonderful behavior , which serves to link the record in the model with the saved picture.
In the case of a query Model B -> ... of any form - behavior worked like a clock, and I received the data I needed, in this case - pictures.
However, when it became a task to build a query of the type
Model B -> Model -> A (with conditions where the sample goes along the Model A fields),
it turned out that the search and pagination work fine, but in the results of the associated Model B there is no trace of behavior ... I just got the model fields, without the “warps” I needed.
No dancing dances with Contain, request order, etc. - did not lead to anything. There is no answer in the google group either.
And today I found another rake, but already with behavior Translate. If you use the instructions , and do as advised there, everything works fine, except for my favorite pegging ...
Namely, you cannot sort by the fields located in the i18n table. Will not work. Only for those fields that are present in explicit form. Like this.
Of course, I do not want to say that sorting a table built through i18n will work quickly, or in principle, will work in a sane manner. Maybe it won’t be. But in this case, if you need to somehow sort the results except id, created, then you have no chance to use this behavior. It will not work. :(
And if the first rake can be bypassed by the second request (first, get the list of id Model B, and then request all records directly from Model B (here the behavior will work). Then in the second rake, the only way to sort is to do without boxed behavior.
2All : If someone solved these issues - share the solution in the comments.This is about CakePHP 1.2.3.8166