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();
}

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.