Is there a way in CakePHP 1.3 to define a model association without having a model for the associated table? For example:
<?php
class SomeModel extends AppModel
{
var $useTable = 'some_table';
var $belongsTo = array(
'AnotherModel' => array(
// association data here
)
);
}
?>
Where AnotherModel doesn’t actually have a model file. I just want to define the table that model would use and the association details. Is this possible?
Quick answer is: It should be fine. Have you tried it? Worse case scenario is it won’t work without the file, so just add the model file. It takes all of two seconds:
Done!
UPDATE
If you follow cake convention on the naming of tables, you should be able to reference the table using the appropriate name without the model file. For example:
However, if you have a table that does not follow convention, you must create a model file that defines
$useTableto indicate which table it relates to:SomeTablewhere$useTable = 'some_table';CustomModelwhere$userTable = 'anotherModel';There is no other way around it. CakePHP is not magic. It needs to know what table is being referenced. Unless you are doing joins. Then in the join you can reference the table.