Association with varchar foreignkey


Hello, I come to ask a question about associations and the foreign key. In the conventions of CakePHP, it is indicated to use a numerical value (example game_id). I would like to know if it is a bad practice to defend a varchar for a foreign key, knowing that the varchar will never change value.

I know it is possible to do this because I have already experienced it, but I do not know if this is a good way to do with CakePHP.

I need a varchar for the foreign key to put a condition on the association. For example, the table taxonomies to the terms table to the table items.

$this->belongsTo('Categories', [
   'className' => 'Terms',
   'conditions' => 'Terms.taxonomy_name' => 'category',
   'foreignKey' => 'category_id'

Thank you :slight_smile:


I think this is much more about database design, not CakePHP related. Integers works better for ids, but you should check by benchmarking what is the difference in performance if you use varchars.