Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6162121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:35:57+00:00 2026-05-23T21:35:57+00:00

I have two tables in my app: ‘Clients’ and ‘Appointments’ In the appointments table

  • 0

I have two tables in my app: ‘Clients’ and ‘Appointments’

In the appointments table I have a foreign key called ‘clientid’ which links the tables together. How would I show the appointments for that user?

So for example when viewing a client /admin/clients/view/201/ I would see the Client details for client 201 and also the appointments for that client.

So far my controller looks like this:

class ClientsController extends AppController
{
    var $name = 'Clients';

    function beforeFilter()
    {
        parent::beforeFilter();
        $this->Auth->allow(array('*'));  
    }

    function admin_view($id = null)
        {
            $this->Client->id = $id;
            $this->set('client', $this->Client->read());
        }

Any help would be much appreciated. Thanks

Edit: Client model

class Client extends AppModel
{
    var $name = 'Client';

    var $useTable = 'clients';
}

Edit2: View

    <h1><?php echo $client['Client']['lastname']; ?> <?php echo $client['Client']['firstname']; ?> (<?php echo $this->Html->link('Edit', array('action' => 'edit', $client['Client']['id'])); ?>)</h1>

    <p><strong>Date of Birth:</strong> <?php echo $client['Client']['dateofbirth']; ?></p>

    <h3>Appointments</h3>

<table>
    <?php foreach ($appointments as $appointment): ?>
        <tr>
            <td>
                <?php echo $this->Html->link($appointment['Appointment']['date'],
                array('admin' => true, 'controller' => 'appointment', 'action' => 'view', $appointment['Appointment']['id'])); ?>
            </td>
        </tr>
    <?php endforeach; ?>
</table>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:35:58+00:00Added an answer on May 23, 2026 at 9:35 pm

    You need to setup hasMany association between Client->Appointment models (see docs, exactly as User->Comment association is), and reverse belongsTo association between Appointment->Client (see same doc).

    If your DB tables and keys are named according to Cake conventions and you’re using PHP 5, this is all that you need:

    class Client extends AppModel
    {
        var $hasMany = 'Appointment';
    }
    
    class Appointment extends AppModel
    {
        var $belongsTo = 'Client';
    }
    

    Recursion is set to 1 (as you need it) by default, so if you haven’t changed it anywhere – your code should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app which allows users to vote and have two tables Video
I have two tables: table a ida valuea 1 a 2 b 3 c
I have two tables one with ID and NAME table 1 ID | NAME
I have two tables user table user_id | name | 1 | peter |
I have two tables, a user table and a application table: User id username
I have two tables connected with one to many relationship. Parent Table is a
I have a situation in Oracle where I have two tables - Table A
I have a simple web-app with Database with two tables. The administrators can modified
I have two tables: Table 1 id app_name app_id 1 name1 12001 2 name2
I have two tables in my database : Order(OrderID, Date, ClientID) OrderItem(OrderID, ProductID, Quantity)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.