CakePHP 4
I have a Cities
table:
CREATE TABLE cities (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(64) NOT NULL,
created DATETIME,
modified DATETIME
);
I also have a Properties
table:
CREATE TABLE properties (
id INT AUTO_INCREMENT PRIMARY KEY,
number INT,
street VARCHAR(64) NOT NULL,
city_id INT NOT NULL,
created DATETIME,
modified DATETIME
);
I am trying to figure out how to $this->paginate($this->Properties)
and have the query return the both Properties.city_id
and Cities.name
.
The Cities
table provides a list of valid cities when adding property records.
How would I set up the associations between these two tables so Properties->find()
always returns the name of the city with Properties.city_id
. I know how to make a query do this, but I want to know the Cake way.