Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
Cakephp - How to get data from other model using associated model?

How to Join two model table to get user name base on user_id?

likesTable.php - id | post_id | user_id

              1      5     23

postTable.php - id | like_id | user_id | content

               5     1    23    Hello
               

userTable.php - id | user_name |

               23  sample_name

PostController

   $this->paginate = [
        'contain' => ['Users', 'Likes'],
    ];
    $posts = $this->paginate($this->posts);

Cake PHP variables in view

 'likes' => object(App\Model\Entity\likes) id:4 {
 'id' => (int) 1
 'post_id' => (int) 5
 'user_id' => (int) 23   ***I want to get user name from this ID***
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Add users with likes in container (Likes.Users)

$this->paginate = [
        'contain' => ['Users', 'Likes.Users'],
];
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!