php - Modifying Containable fields required in beforeFind callback? -


In my KPPP 1.2.5 app, I have a profile model that is the user The model user model has a username field, and when I execute find () on the profile model, I always automatically User.username also

This is what I tried to do:

 

  before the public event ($ queryData) {// Determine that the username is already un Locking in that return data has been 'User.username' or 'User' = & gt; Array ('username'). $ Uuserdata = release ($ querydata ['contains']) & amp; Amp; In_array ("user. {$ This-> user- & gt; displayField}", $ queryData ['contain']); $ Uuser data | = Release ($ query data ['include'] ['user']) & amp; Amp; In_array ($ this-> User-> displayField, $ queryData ['contains'] ['user']); // Request that the user's data should be included, if the calling method has not already been requested ($! UserData) {$ queryData ['contain'] ['user'] [] = $ this- & Gt; User- & gt; DisplayField; } $ QueryData; }  

I can see that the value of $ queryData ['contain'] is being updated properly, but the user name will not be retrieved Used to be. I looked at the CakePHP core code for the search () method, and I found that the beforeFind () callback is being called after the callback of all the behaviors, which means That's what needs to be done with the already containable $ queryData ['contain'] before I was able to modify it.

How can I work without the core?

I have solved it, so here's my answer because someone has the same complexity. The containable fields can not be specified in the first, before all the biologists' () methods before before the model beforeFind () Method is called. >

In this way, to add to my custom containable field, it was necessary to modify the find () method directly on my profile model.

  public work ($ terms = zero, $ field = array), $ order = zero, $ recursive = zero) {$ this-> ("{$ This-> user- & gt; nickname}. {$ This-> user- & gt; displayField}"); Return Parent :: Find ($ terms, $ fields, $ order, $ recursive); }  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -