views:

48

answers:

3

Hello guys,

I am using cakephp 1.3, I am having a small issue,please help

I have 2 tables in my database Profiles and qualifications, Profiles belongs to qualifications and qualifications has many profiles. qualification display_field is set to 'qualification', I used cake bake all for creating CRUD, when I try to add profile I get the values from qualification field in drop down list ( instead of id), but when view all the profiles, the list showing qualification id instead of the values in qualification, I would like to view the qualification value instead of qualification primary key id in the list,

I can change the value from the view file, but I would like to know is there any way that I can show the values automatically without modifying the index view file for profiles

Thank you very much guys

A: 

I don't think so.

It's just a simple modification though: go to your profiles/index.ctp file and change:

$profile['Profile']['qualification_id'];

to

$profile['Qualification']['qualification'];

I don't think that there is a way to tell bake what the display field on the list should be. Though I guess its a good point and could be added as an enhancement to new versions.

Still, what you have to remember is, that bake will only get you the basics, so you don't have to write simplest code, but some alterations are almost always necessary.

PawelMysior
thank you very much, great advice
Thomas John
I would imagine this wouldn't be an issue if your `qualifications` database table followed conventions and had a `name` or `title` field. http://book.cakephp.org/view/1014/Titles
deizel
@deizel - that could be true and it actually should be named `name`. Still, bake should consider `display_field` nonetheless.
PawelMysior
problem isn't his templates - it is his display_field property needing to be displayField in his models. Stating that bake doesn't do the displayField properly (at least when I test it just now) is a fallacy - my tests show it working just fine.
Abba Bryant
well, if that's the case, sorry for the misguide. Your answer should be marked as "The One".
PawelMysior
A: 

that usually happens with cake bake "all"

dont use "all" but manually go through it (hit enter several times then). this will bake your relations correctly

i had this problem, too, and solved it this way (probably a bug, but didnt have time to dig into it deeper).

by the way: it is also important that your recursive level is > 0 for this to work! i usually have -1 in app model (as default value)

but for new models i set it inside the model to 2 in order to bake all relations (as you described). after that i just remove it again and it is -1 as default again (which is actually what is is supposed to be if you dont want a lot of work with setting recursive levels all the time).

mark
+2  A: 

Cake should handle the displayField property in the model while baking and running a quick test from my local machine shows that it does work as expected.

Reading over your initial question you are setting $Model->display_field instead of $Model->displayField.

Notice the camelCase on the property name.

<?php
    class Qualification extends AppModel
    {
        ...
        public $display_field = 'qualification';
        ...
        // when it should be
        ...
        public $displayField = 'qualification';
?>

Let me know if that fixes the problem. You shouldn't have to screw with the indexes in the baked files. Especially if you use bake to do one Controller at a time and the Models are all already either baked or ready to use.

Abba Bryant