Search code examples
cakephprelationshipcakephp-3.0cakephp-bake

Form select options access desire field from foreign key table in cakephp 3.x.x


In my Project I have items table this contain two foreign Keys locations_id and categories_id. When i add new item, cateogries_id appear categories.name
in add.ctp : select options (foreign) Key is display Id. I want to appear at location select option locations.city field from location table.
this is used by cake bake command to my all tables.!
Thanks My Project Sample image clear!


Solution

  • \src\Model\Table\LocationsTable.php Change Display Field. this is show Id .. now Change $this->displayField('id'); To $this->displayField('name'); /*name is your field in you table you want to display
    enter image description here