Cakephp related tables show id’s instead of values

Whenever CakePHP automagically fetches lists from your tables, it uses the idkey for the value and the $displayField for the text.

If your table has a name or title field, CakePHP automatically displays it as the display field. So, either rename the field that you want as your display field (say, candidate_name to just name) or set the $displayField variable in your model:



Whenever CakePHP automagically fetches lists from your tables, it uses the idkey for the value and the $displayField for the text.

If your table has a name or title field, CakePHP automatically displays it as the display field. So, either rename the field that you want as your display field (say, candidate_name to just name) or set the $displayField variable in your model:

 

class Candidate extends AppModel {

    var $displayField = ‘candidate_name’;

}

 

If there is no other data being stored in the qualificationlookups table, change the relationship to candidates -> HABTM -> qualifications.

To do this, you first need to drop the qualificationlookups table. Create a new table called candidates_qualifications with two indexes,candidate_id and qualification_id.

In your Candidate and Qualification models, define a HABTM Relationship. You do not need to make a new CandidatesQualificationModel, cake will do it on the fly.

From: http://pinoytech.org/question/4558505/cakephp-related-tables-show-ids-instead-of-values

Leave a Reply

Your email address will not be published. Required fields are marked *