Note that there are some explanatory texts on larger screens.

plurals
  1. PODatabase Pick List in CakePHP?
    primarykey
    data
    text
    <p>I'm designing the database for a mental health agency where the clinicians choose from a list of pre-formatted choices for a lot of categories (employment status, housing status, relationship status, etc.) In a previous iteration of the database, we used a pick list similar to one described on stackoverflow <a href="https://stackoverflow.com/questions/86992/how-do-you-manage-pick-lists-in-a-database">here</a> to avoid creating tables for each of these lists.</p> <p>We're planning on using CakePHP as the framework for the new build and I'm concerned about CakePHP's "automagic" ability to save and display data easily not playing nicely with a database that uses the pick list structure. I'm considering creating a separate table for each list to take advantage of CakePHP's automagic.</p> <p>Does anyone have experience implementing a pick list in CakePHP or have a suggestion regarding an alternative design approach?</p> <p>EDIT: I'm trying to implement this using two tables -</p> <pre><code>value_lists list_values ----------- ------------------------------- id | list_name id | list_value | value_list_id </code></pre> <p>Here is my model code:</p> <pre><code>&lt;?php class BirthplaceCounty extends AppModel { var $name = 'BirthplaceCounty'; //The Associations below have been created with all possible keys, those that are not needed can be removed var $useTable = 'list_values'; var $displayField = 'list_value'; var $hasMany = array( 'Registration' =&gt; array( 'className' =&gt; 'Registration', 'foreignKey' =&gt; 'birthplace_county_id', 'dependent' =&gt; false, 'conditions' =&gt; array('BirthplaceCounty.value_list_id' =&gt; '8'), 'fields' =&gt; '', 'order' =&gt; '', 'limit' =&gt; '', 'offset' =&gt; '', 'exclusive' =&gt; '', 'finderQuery' =&gt; '', 'counterQuery' =&gt; '', ) ); </code></pre> <p>}</p> <p>My issue seems to be that no matter what conditions I try -</p> <pre><code> $this-&gt;BirthplaceCounty-&gt;find('list'); or $this-&gt;BirthplaceCounty-&gt;find('all'); </code></pre> <p>always returns all of the records in list_values. The SQL that CakePHP is producing is</p> <pre><code>SELECT `BirthplaceCounty`.`id`, `BirthplaceCounty`.`list_value` FROM `list_values` AS `BirthplaceCounty` WHERE 1 = 1 </code></pre> <p>No matter how I change the condition, the WHERE clause is always 1 = 1. How do I write the conditions correctly?</p> <p>EDIT 2: Ok - I realized that setting conditions in the $hasMany variable won't affect the find() function. I created a new function that works.</p> <pre><code>function getActual() { $conditions = array('BirthplaceCounty.value_list_id = 5'); return $this-&gt;find('list', compact('conditions')); } </code></pre> <p>Is the only way to do this by overloading the find() function?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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