TP中關聯模型的使用

2022-03-09 16:48:08 字數 911 閱讀 7084

class bfinanceproduct extends common

/*** @desc 屬性、屬性值

*/public function attrvalue()

/*** 金融型別

*/public function type()

/*** @param $where

* @param string $field

* @desc 根據條件獲取金融產品資料

* @date 2020/5/26

*/public function getfinanceproductbycondition($where,$field='*',$order='sort desc')

return $data;

}/**

* @param $where

* @desc 獲取金融產品詳情、關聯數

*/public function getinfobycondition($where)else}}

用金融產品的模型類作為例子:

$data = $this->getlist($map,$field,$order);
查詢列表的時候,每條資料對應的機構、分類都是一對一的關係所以用法如下
$data->load(['organs','type']);

對應的屬性和屬性值是多對多的關係,所以寫法如下

$data->load(['attrvalue'=>['attrname']]);

其中 type、organs、attrvalue 方法定義了他們之前的關係,以及關聯條件,避免了平時我們取出資料對資料關係的處理。

其中注意isempty()的用法

1.{} 2.

只有第二種才能使用改方法判斷。

by:jff

tp5 模型關聯

二 文章中用到的表結構 image 表,儲存的位置資訊 banner 推薦位表,儲存推薦位的型別 banner item 表,推薦位中的資訊條目,可以看到它擁有外來鍵 img id theme 表,商品活動主題,包含頭圖,主題圖 product 表,商品表 theme product 表,theme...

例項講解TP5中關聯模型

二 文章中用到的表結構 image 表,儲存的位置資訊 banner 推薦位表,儲存推薦位的型別 banner item 表,推薦位中的資訊條目,可以看到它擁有外來鍵 img id theme 表,商品活動主題,包含頭圖,主題圖 product 表,商品表 theme product 表,theme...

有關TP5 模型關聯隨筆

一對一關聯 hasone 關聯模型 外來鍵 主鍵 關聯模型 必須 關聯的模型名或者類名 外來鍵 預設的外來鍵規則是當前模型名 不含命名空間,下同 id 例如user id 主鍵 當前模型主鍵,缺省會自動獲取也可以指定傳入 一對多關聯 hasmany 關聯模型 外來鍵 主鍵 關聯模型 必須 模型名或者...