Note that there are some explanatory texts on larger screens.

plurals
  1. POConstructing a select element using a foreign key relationship
    text
    copied!<p>Here's my simple database schema and models:</p> <pre><code>create table personas --done ( id int primary key AUTO_INCREMENT, nombre varchar(128), apellido varchar(128), fecha_de_nacimiento date, sexo Bool, carnet_de_identidad varchar(64), direccion_domicilio varchar(128), direccion_oficina varchar(128), ciudad varchar(128), estado varchar(128), pais varchar(128), email_principal varchar(512), email_secundario varchar(512), telefono varchar(64), movil varchar(64), titulo_profesional varchar(128), universidad varchar(128), foto_archivada blob, curriculum text, comentarios text ); create table coordinadors ( id int primary key AUTO_INCREMENT, persona_id int, FOREIGN KEY (persona_id) REFERENCES personas(id) ); # My CakePHP models: class Persona extends AppModel { public $hasOne = array('Tutor'); // Some other relationship ommitted for brevity. } class Tutor extends AppModel { public $belongsTo = 'Persona'; } </code></pre> <p>I'm trying to create an HTML <code>&lt;select&gt;</code> element with only <code>persona</code> objects that are <code>coordinadors</code>. In plain English, that would be: <code>Show me a collection of all the persona choices who are coordinadors.</code></p> <p>Here's what I have so far:</p> <pre><code>$coordinadores = $this-&gt;Coordinador-&gt;find('all'); Output: array( (int) 0 =&gt; array( 'Coordinador' =&gt; array( 'id' =&gt; '3', 'persona_id' =&gt; '2' ), 'Persona' =&gt; array( 'id' =&gt; '2', 'nombre' =&gt; 'Sergioa', 'apellido' =&gt; 'Tapia', 'fecha_de_nacimiento' =&gt; '2012-10-01', 'sexo' =&gt; false, 'carnet_de_identidad' =&gt; '215154', 'direccion_domicilio' =&gt; 'qwerqwerqwer3', 'direccion_oficina' =&gt; 'qwerqwerwqerqwer', 'ciudad' =&gt; 'Sqwerqwerwqerra', 'estado' =&gt; 'Sqwerqwerqwerquz', 'pais' =&gt; 'qwerqwerqwerqwer', 'email_principal' =&gt; 'serqwerqwerqwerm', 'email_secundario' =&gt; 'stqwerwqerqwercom', 'telefono' =&gt; 'qwerqwerqwer', 'movil' =&gt; 'qwerqwerqwer', 'titulo_profesional' =&gt; 'Ing qwerqwerqwer', 'universidad' =&gt; 'qwerqwerqwer', 'foto_archivada' =&gt; null, 'curriculum' =&gt; '&lt;p&gt;oiasdfoiwecwec&lt;/p&gt;', 'comentarios' =&gt; '&lt;p&gt;jojqwefijwecwc wecwec&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;wcwecwec&lt;/p&gt;' ) ) ) </code></pre> <p>How can I use the Persona obeject to create a simple <code>&lt;select&gt;</code> element?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload