containable - How do I sort or do a find in CakePHP based on deep model associations? -


I have a user table, a role_mail table and a roles table.

Role_email table contains a user_id and a role_id because there can be many roles.

I have a datatyaw in which there are user IDs, emails, names and roles. I can easily sort and filter based on the field in the user table. The way data works, there is a search box that searches for all fields. Therefore, my search query try to sort on a "ORAC should be" where search_term such as username or search_term such as email or search_term such role_name

The problem occurs when I base roll names Filter I am If I want to sort by rollmember. Roll. Search by name or rollmember. Roll.name How can I do this?

My options are as follows: $ sOrder = array ('User.full_name' = & gt; 'ACC'); if (isset ($ params ['iSortCol_0'])) {$ sOrder = array (); ($ I = 0; $ i & lt; intval ($ params [ 'iSortingCols']); $ i ++) {if ($ params [ 'bSortable _'] interval ($ params [ 'iSortCol _'. $ I ])] == "true") {$ sOrder [$ column (lag ($ params [ 'iSortCol _'. $ i])] = $ params [ 'Srtdayr _'. $ i]; array ( 'role' 'Example'), 'allowed space'), 'border', '' '' '' '' '& gt; Array ('rollmember' => gt; = & gt; $ limit, offset '= & gt; $ offset); If (ezet ($ params ['search'])) {$ search_term = '%' $ Params ['search'] '%'; $ Find_options [ 'conditions'] = array (' or '= & gt; array (' User.full_name like '= & gt; $ search_term,' User.email LIKE '= & gt; $ search_term,' User.username LIKE '= & gt; $ search_term //'RoleMember.Role.name' like '=> $ search_term,)); }

will surely work but if you do not have your cache So it would be very disabled ... Try now -

  $ options [joins] = array (array ('table' = & gt; 'role_members',' alias' = ' & gt; 'Rolmember', 'type' = & gt; INNER ',' conditions' = & gt; array ( 'RoleMember.user_id = User.id')), array ( 'table' = & gt; 'roles' , 'Alias' = & gt; role', 'type' = & gt; 'INNER', 'conditions' => array (' RoleMember.role_id = Role.id '))); // Here we have joined all the tables, so the positions in all areas are available ... $ option ['conditions'] = array (' OR '=> array (' User.full_name like '=' & gt; $ search_term, 'Upyogkrtakmel like' = & gt; $ search_term, 'user. name like' = & gt; $ search_term like 'Role.name' = & gt; $ search_term,)); $ User = $ this- & gt; User- & gt; Search ('all', $ option);    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -