0

I have a current_day_users table and users table.What is the better coding practice between the following to extract data from current_day_users:

1.UsersTable.php code

   $this->CurrentDayUsers->find()->where(['user_id'=>$userId,'created'=>$dateToday])->first();
  1. UsersTable.php code

    $this->CurrentDayUsers->findUser($userId,$dateToday);

CurrentDayusersTable.php code

public function findUser($userId,$date){
    return  $this->find()->where(['user_id'=>$userId,'created'=>$date])->first();
}
user727728
  • 733
  • 2
  • 8
  • 21

1 Answers1

0

If you already have CurrentDayUsers table, I'd suggest you to follow the second approach:

public function findUser($userId,$date){
   return  $this->find()->where(['user_id'=>$userId,'created'=>$date])->first();
}

This is provides a clean and compact code instead of using the query builder within Users Table.

Indrasis Datta
  • 8,692
  • 2
  • 14
  • 32