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 8630979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:09:09+00:00 2026-06-12T09:09:09+00:00

Here’s my database schema: create table Personas ( id int primary key AUTO_INCREMENT, Nombre

  • 0

Here’s my database schema:

create table Personas
(
    id int primary key AUTO_INCREMENT,
    Nombre varchar(255),
    Apellidos varchar(255),
    FechaDeNacimiento date,
    Sexo Bool,
    CarnetDeIdentidad varchar(255)
);

create table Tutors
(
    id int primary key AUTO_INCREMENT,
    persona_id int,
    FOREIGN KEY (persona_id) REFERENCES Personas(id)
);

create table Alumnos
(
    id int primary key AUTO_INCREMENT,
    persona_id int,
    FOREIGN KEY (persona_id) REFERENCES Personas(id)
);

create table CoordinadorDeProgramas
(
    id int primary key AUTO_INCREMENT,
    persona_id int,
    FOREIGN KEY (persona_id) REFERENCES Personas(id)
);

And here are my Model declarations:

<?php
class Alumno extends AppModel {
    public $belongsTo = 'Persona';
}

<?php
class Coordinadordeprograma extends AppModel {
    public $belongsTo = 'Persona';
}

<?php
class Tutor extends AppModel {
    public $belongsTo = 'Persona';
}

<?php
class Persona extends AppModel {
    public $hasOne = array('Alumno', 'Tutor', 'Coordinadordeprograma');
}

In my Controller I just want to fetch all Persona records if they have a foreign key relationship in Alumnos (for example).

Here’s my code, I hope it illustrates what I’m trying to do:

public function filter($type = null) {
    if ($type == "alumno") { // www.app.com/personas/filter/alumno
        $this->set('personas', $this->Alumno->Persona->find('all'));
    }
}

However this is returning every single Persona record, and not just the ones that have a record in the Alumno table.

How do you suggest I solve this problem? I thought that by using $this->Alumno->Persona I would only be reaching for Persona’s that are in the Alumno table.

Thanks!

  • 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-06-12T09:09:10+00:00Added an answer on June 12, 2026 at 9:09 am

    You could use the containable behaviour and just make a find on Alumno??

    $this->set('personas', $this->Alumno->find('all'));
    

    it should retrieve the ‘Alumno’ with all the models associated to it. You could also choose which models you want to retrieve. For example, this code will retrieve all the ‘Alumno’ with its corresponding ‘Persona’

    $this->set('personas', $this->Alumno->find('all',array('contain'=>array('Persona')));
    

    An of course.. like @Paulo answered, you could manually make the join, but using “containable” is cleaner. I only make the join manually when I don’t have any other solution.

    Hope this helps,

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

Sidebar

Related Questions

Here is my SQL script CREATE TABLE tracks( track_id int NOT NULL AUTO_INCREMENT, account_id
Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`
Here's an example query: DECLARE @table table (loc varchar(10)) INSERT INTO @table VALUES ('134a'),
Here is a simplification of my database: Table: Property Fields: ID, Address Table: Quote
Here's my procedure: DROP PROCEDURE IF EXISTS `couponExpires`$$ CREATE DEFINER=`root`@`localhost` PROCEDURE `couponExpires`(IN couponID BIGINT,
Here is my problem : I have a post controller with the action create.
Here is an example. foreach (var doc in documents) { var processor = this.factory.Create();
Here's what my table TheTable looks like ColA | ColB | ColC ------+-------+------ abc
Here is a code snippet I was working with: int *a; int p =
Here is my class: public class A{ private void doIt(int[] X, int[] Y){ //change

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.