Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I don't see any problem in using that with CakePHP. I understand when @Anh Pham says that it could be "quite a hassle", but honestly almost anything database-related can become a hassle in Cake if your site is a little more complex than the blog tutorial.</p> <p>Cake is my PHP framework of choice, but I believe you have to use it for a while and try to understand how the "magic" works. When you do, it's much easier to decide when you should let Cake handle some database operation by itself, and how to trick it into doing what you want in an elegant way. </p> <p>That "pick list" structure can be made to play nice with Cake's model associations, it's just a matter of adding the right <code>conditions</code> and <code>foreignKey</code> when declaring the association. </p> <p><strong>UPDATE</strong></p> <p>I can see from the latest edits that you are on the right track. I believe you now understand why your <code>$this-&gt;BirthplaceCounty-&gt;find('list')</code> call was returning the whole table: the model doesn't know that you want to filter by <code>value_list_id = 5</code> (5 or 8?), that condition only applies to its association with the other model.</p> <p>Anyway, you do have another options beside overloading <code>find()</code>: you can define the default condition inside the model's <code>beforeFind</code> callback, like this:</p> <pre><code>function beforeFind($queryData) { $defaultConditions = array("BirthplaceCounty.value_list_id = 5"); if(!empty($queryData['conditions'])) { // Make sure 'conditions' is an array, so we can array_merge $queryData['conditions'] = is_array($queryData['conditions']) : $queryData['conditions'] : array($queryData['conditions']); // Merge conditions passed to find with the default $queryData['conditions'] = array_merge($defaultConditions, $queryData['conditions']); } else { $queryData['conditions'] = $defaultConditions; } // Return the modified $queryData to be used by find return $queryData; } </code></pre>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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