I have models like below

**Customer.rb**

```
has_many :appointments
has_many :addresses
has_many :contacts

```

**Address.rb**

```
belongs_to :customer

```

**Contact.rb**

```
belongs_to :customer

```

**Appointment.rb**

```
belongs_to :customer

```

I have defined API's to return customers like below but with one extra attribute i.e appointment\_id.

```
customers: [
  {
    appointment_id: 'xxxxxxx'
    ..
    ..
    ..
    addresses: [{...}, {...}]
    contacts: [{...},{...}]
  },
  {
    ..
  },
  .....

]

```

The above api is defined in a way that I pass *@customers* (which is array of customers along with their nested objects address, contacts). Problem is How should write active record query to return so so data.

***Current Approach:***

*// I got list of appointment id's and I should return corresponding customers data as shown in above api.*

```
cust_ids    = Appointment.where(blah blah blah).pluck(:customer_id)
@customers =  Customer.where(appointment_id: cust_ids).includes(:addresses, :contacts)

```

**What I want?** 

My above approach doesnt have appointment\_id in @customers object. How should I get it? Do I need to join table
 along with includes. ??