# Help with associations

**URL:** <https://discourse.cakephp.org/t/help-with-associations/11090>\
**Category:** Need Help\
**Tags:** help\
**Created:** [March 28, 2023, 2:14am UTC](https://discourse.cakephp.org/t/help-with-associations/11090 "2023-03-28T02:14:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![palinst](https://avatars.discourse-cdn.com/v4/letter/p/73ab20/32.png) [@palinst](https://discourse.cakephp.org/u/palinst)\
**Post date:** [March 28, 2023, 2:14am UTC](https://discourse.cakephp.org/t/help-with-associations/11090/1 "2023-03-28T02:14:23Z")

</div>

CakePHP 4

I have a `Cities` table:

```auto
CREATE TABLE cities (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(64) NOT NULL,
    created DATETIME,
    modified DATETIME
);

```

I also have a `Properties` table:

```auto
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.

---

<div class="post-metadata">

**Author:** ![palinst](https://avatars.discourse-cdn.com/v4/letter/p/73ab20/32.png) [@palinst](https://discourse.cakephp.org/u/palinst)\
**Post date:** [March 28, 2023, 3:12am UTC](https://discourse.cakephp.org/t/help-with-associations/11090/2 "2023-03-28T03:12:50Z")

</div>

I used Bake to create my files for me and now it all works great!

---

<div class="post-metadata">

**Author:** ![bgrinter](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/bgrinter/32/1381_2.png) [@bgrinter](https://discourse.cakephp.org/u/bgrinter)\
**Post date:** [March 29, 2023, 4:48am UTC](https://discourse.cakephp.org/t/help-with-associations/11090/3 "2023-03-29T04:48:30Z")

</div>

Baking is a great way to generate code and get an understanding - real helper
