From ff7c860a62589968186c2bdf8a275a6b6f19f67c Mon Sep 17 00:00:00 2001 From: yunwuxin <448901948@qq.com> Date: Fri, 3 Mar 2017 12:04:06 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E8=BD=BDBelongsToMany=E7=9A=84selectO?= =?UTF-8?q?rFail=20findOrFail=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../think/model/relation/BelongsToMany.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index 53d80f65..015d86d5 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -159,6 +159,28 @@ class BelongsToMany extends Relation return $result; } + /** + * 查找多条记录 如果不存在则抛出异常 + * @access public + * @param array|string|Query|\Closure $data + * @return array|\PDOStatement|string|Model + */ + public function selectOrFail($data = null) + { + return $this->failException(true)->select($data); + } + + /** + * 查找单条记录 如果不存在则抛出异常 + * @access public + * @param array|string|Query|\Closure $data + * @return array|\PDOStatement|string|Model + */ + public function findOrFail($data = null) + { + return $this->failException(true)->find($data); + } + /** * 根据关联条件查询当前模型 * @access public