Just gettign into MVC developement and cakes implimentation, so I'm getting confused with table naming and id references.
I hava a table called Assets and value sotered in Assets is asset_status_id field which is meant to be a reference to the table Asset_Statuses this table is a simple list of possible statuses the assets could be in at any one time (Active, Inactive, Sold, Maintenace etc) I have chosen to use a table for this list as a) I think I'll need to add more options at some time b) I have a 'sequence' field in this table so I can control the sort order they will apear in in any drop downs.
'Cake Bake'ing seems to see a table called Asset_Statuses as an indication it exists to descibe a relations ship between the Assets table and a non-existent Statuses table. Now I know what your thinking just call the table Statues right? But I have oither 'Status' tables I'd like to use such as a Domain_Status which wont use the same status lists of course.
So what s the naming convention I should be using to make this all work easily?
I am not sure that the plural of Asset Status is Asset States (you should check) and also the table need to be lower case, so asset_states, not Asset_States. But you can use a totally different table in your models. Check this. So basically create a model, name it as you like. I.e. AssetState and put:
var $useTable = 'asset_states';
and I think you won't have problems. Just be sure that in your relation belongsTo, hasMany you provide the proper class name i.e.:
var $belongsTo = array(
'AssetState' => array(
'className' => 'AssetState' //Most important
)
);
you might just be better off using a statuses table, as it can be used all over and not just for the assets. this can be done easily adding a model field, so its id, model, status.
then your join just has a condition.
class Asset extends AppModel{
var $belongsTo = array(
'Status' => array(
'className' => 'Status' // not needed with the proper conventions and not in a plugin,
'conditions' => array('Status.model' => 'Asset')
)
);
}
you can use a behavior to automate the setting of the model field in beforeSave
As a side note, all tables should be all lower case, not the funny case you are using. This may be the cause of things not working the way they should.