use Cake\ORM\Table; class ProjectsTable extends Table { public function initialize(array $config) { parent::initialize($config); // Create an alias for the Users table $this->belongsTo('Clients', [ 'className' => 'Users', 'foreignKey' => 'client_id' ]); } }
$query = $this->Projects->find('all') ->contain(['Clients']) ->select(['Projects.title', 'Clients.name']);In this example, we are querying the "Projects" table and using the alias "Clients" to join with the "Users" table. We are also selecting only the "title" column from the "Projects" table and the "name" column from the "Clients" table. Overall, cake.orm provides a powerful set of tools for working with databases in PHP, and its ability to alias tables is just one of the many features that make it a valuable package library for developers.