Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6705315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:23:23+00:00 2026-05-26T07:23:23+00:00

I am trying to force a join on paginate function of cakephp. A user

  • 0

I am trying to force a join on paginate function of cakephp.
A user has messages which means it will be message belongs to user.
I have to show them in a list so i need to use paginate here.
Problem is it doesnt shows me the record of the model which i intend to bind
My code is:

$userId     = $this->Session->read('SESSION_ADMIN.id');
        $this->helpers['Paginator'] = array('ajax' => 'Ajax');

      $this->Message->bindModel(
           array(
             'belongsTo'=>array(
                 'Npo'=>array(
                   'className'  =>  'Npo',
                 'foreignKey' => 'reciever_id',
                 'fields'     => 'Npo.username'
               )          
           )
        )
    );
    $this->paginate = array('conditions'=>array('Message.sender_id'=>$userId,'Message.sender'=>'Admin'),
                            'order'     => array('Message.modified DESC'),
                            'limit'     =>'1'
                              );     
    $sentMsg =  $this->paginate('Message');
    //$sentMsg =  $this->Message->find('all');
    pr($sentMsg);die();

when i uncomment the FIND statement it shows me record but in case of paginate it doesnt.
Also it doesnt shows me the join in the paginate query but it does in counting record.
Any one have an idea.I dont want to use paginate Join here.Is there a way to enforce a belongs to here?

Regards
Himanshu Sharma

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:23:24+00:00Added an answer on May 26, 2026 at 7:23 am

    Have you tried:

    $this->Message->bindModel(
               array(
                 'belongsTo'=>array(
                     'Npo'=>array(
                       'className'  =>  'Npo',
                     'foreignKey' => 'reciever_id',
                     'fields'     => 'Npo.username'
                   )          
               )
            ), false // Note the false here!
        );
    

    The paginator actually executes two queries: one to count the total number of records, and one to actually fetch the desired records. By default, associations created on the fly using bindModel() are reset after each query. It depends on the Cake version which query comes first, but I believe that in your case it is the count query; leaving the actual results query without the association. Setting false on on the second argument of bindModel() prevents the association from being reset after the first query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to show only brand instances which the current user has not tagged,
I am trying to force user to enter username and password when they run
I am trying to force the user to download a file. For that my
I'm trying to force Linq to preform an inner join between two tables. I'll
I'm trying to force a keypress inside a textfield using Javascript. This has to
I'm trying to force a user to be redirected to the non-www website, and,
I am trying to force a user to login once they call this update
I am trying to force a user to select a date in the future
I'm trying to force inline a member function and I get the error: a_class::mem_func(),
I'm trying to force SSL on my site. I want to have a ring

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.