This recipe shows how to use Containable
to specify what related models are returned as a result of a find
operation. It also shows us how to limit which fields are obtained for each association.
To go through this recipe we need some sample tables to work with.
1. Create a table named
families
, using the following SQL statement:CREATE TABLE `families`( `id` INT UNSIGNED AUTO_INCREMENT NOT NULL, `name` VARCHAR(255) NOT NULL, PRIMARY KEY(`id`) );
2. Create a table named
people
, using the following SQL statement:CREATE TABLE `people`( `id` INT UNSIGNED AUTO_INCREMENT NOT NULL, `family_id` INT UNSIGNED NOT NULL, `name` VARCHAR(255) NOT NULL, `email` VARCHAR(255) NOT NULL, PRIMARY KEY(`id`), KEY `family_id`(`family_id`), CONSTRAINT `people__families` FOREIGN KEY(`family_id`) REFERENCES `families`(`id`) );
3. Create a table named
profiles
, using the following SQL statement:CREATE TABLE `profiles`( `id` INT UNSIGNED AUTO_INCREMENT NOT NULL...