# 關聯模型$this->hasOne(關聯模型的類名, 關聯模型的外鍵, 當前模型的主鍵); $this->belongsTo(關聯模型的類名, 當前模型的外鍵, 當前模型的主鍵); $this->hasMany(關聯模型的類名, 關聯模型的外鍵, 當前模型主鍵 ...
關聯模型三類 .一對於 hasOne .一對多 hasMany .屬於 belongsTo .對對多 belongsToMany 三種關聯的時候。 .按從屬結構,分兩種,父子結構。同級結構。 .記住這兩個結構。會可以很方便的記憶,三個函數的參數。 父hasOne 子子父 ABBA 父hasMany 子子父 ABBA 子belongsTo 父父子 BAAB A belongsToMany B C B ...
2020-05-27 14:30 0 804 推薦指數:
# 關聯模型$this->hasOne(關聯模型的類名, 關聯模型的外鍵, 當前模型的主鍵); $this->belongsTo(關聯模型的類名, 當前模型的外鍵, 當前模型的主鍵); $this->hasMany(關聯模型的類名, 關聯模型的外鍵, 當前模型主鍵 ...
后面的bind 就可以吧StoneModel模型中的 name字段綁定到當前模型中的stone_name字段中 這樣就可以達到不顯示綁定模型中多余字段的目的 並且在當前模型獲取數據時不會禪城多個數據層級 ...
// 查詢用戶昵稱是think的用戶 // 注意第一個參數是關聯方法名(不是關聯模型名) $users = User::hasWhere('profile', ['nickname'=>'think'])->select(); // 可以使用閉包查詢 $users ...
...
1.模型中建立關聯關系 ...
文章表SQL CREATE TABLE `tp_article` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主鍵ID', `title` varchar(50) DEFAULT NULL COMMENT '標題', `add_time ...
在一個模型中,新建方法實現外鍵關聯 hasOne(關聯模型,關聯模型主鍵,當前模型外鍵) bind('name'),將關聯模型得name屬性綁定到當前模型 通過with關聯表使用該方法 ...
控制器: 模型Article.php 模型Comment.php ...