讓我們例如在http://book.cakephp.org/2.0/en/models/associations-linking-models-together.htmlCakePHP命名約定:需要顯式聲明嗎?
使用實體Recipe
和Ingredient
並按照約定找到的文檔,在hasAndBelongsToMany
關係,連接表將被稱爲ingredients_recipes
。
據我瞭解,下面的命名約定的一點是讓cakePHP
做的班級自動佈線而無需顯式聲明一些變量,在這種情況下,該表的名稱:ingredients_recipes
現在,在下面的示例中(直接從上面的鏈接中提取),它們明確地聲明'foreignKey' => 'recipe_id'
,'associationForeignKey' => 'ingredient_id'
和'joinTable' => 'ingredients_recipes'
。
我的問題是:即使我遵循了表,外鍵等的命名約定是否必須顯式聲明連接表,外鍵等的名稱,或者它們是否在示例中聲明下面只是爲了向讀者展示一個可能的輸入值?
// Example extracted from the documentation
class Recipe extends AppModel {
public $hasAndBelongsToMany = array(
'Ingredient' =>
array(
'className' => 'Ingredient',
'joinTable' => 'ingredients_recipes',
'foreignKey' => 'recipe_id',
'associationForeignKey' => 'ingredient_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'with' => ''
)
);
}