<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 查詢 本文檔已 小打卡模型為例,講解查詢函數的一些作用。 首先列出小打卡的模型結構: 1 打卡計劃 2 用戶 3 評論 4 標簽 5 點贊 | 模型 | 關系 | 詳解 | | --- | --- |--- | | 打卡計劃-參加用戶 | 1:N | 一個打卡計劃可以很多人參加 | |打卡計劃-所屬用戶|1:1|一個打卡計劃的創建者只有一個| |打卡計劃-評論|1:N|一個打卡計劃有很多評論| |打卡計劃-標簽|1:N|一個打卡計劃有很多標簽| |打卡計劃-點贊|N:N|不同的人可以對不同的打卡計劃點贊| 基于以上模型 我們繼續講解下面內容 ## 創建模型實體 ``` var plan = new Mogo.Model("Plan"); // 這個plan 有下面的所有方法 ``` ## 查詢列表 find(page=1) 我們經常會使用列表查詢來展示內容 ``` let plan = new Mogo.Model("plan"); plan.find().then(res => { console.log(res); }); // 如果需要第二頁的數據 plan.find(2).then(res => { console.log(res); }); ``` 返回結果如下 ![](https://box.kancloud.cn/1252ae432d9bbdf5641d960d77712f35_856x282.png) ## 查詢個體 findOne(id) 我們也會進入詳情查看打卡的具體信息 ``` // 查詢id 為5 的打卡計劃詳情 plan.findOne(5).then(res => { console.log(res); }); ``` 結果如下 ![](https://box.kancloud.cn/f751c631addf9126e82c90478291d046_793x197.png) ## 條件 where(object) 對于有各種條件的查詢可以使用where where可用于搜索,類別查詢 ### 搜索 搜索`title`含有`劉`的打卡 ``` let plan = new Mogo.Model("plan"); plan .where({ title: ["like", "劉"] }) .find() .then(res => { console.log(res); }); ``` where的使用是借助tp5where的封裝,因此支持tp5 where的查詢功能,具體[查閱文檔](http://www.hmoore.net/manual/thinkphp5/135182) 對于復雜查詢,前端可以直接問后端 ## 排序 order(string) + id desc 逆序 (3,2,1) + id asc 正序 (1,2,3) 如果我們想對`id`進行正序(1,2,3) ``` let plan = new Mogo.Model("plan"); plan .where({ title: ["like", "劉"] }) .order("id asc") .find() .then(res => { console.log(res); }); ``` 甚至可以對錢,積分進行排序獲得排行榜的功能。 ## 關聯 with([string,....]) 上面提到各種對應關系 ,可以根據后端提供的關聯填入對應關系 ``` let plan = new Mogo.Model("plan"); plan .where({ title: ["like", "劉"] }) .order("id asc") .with(["owner", "comment.user", "joiner", "tags"]) // 獲取打卡計劃關聯的數據 .find() .then(res => { console.log(res); }); ``` ## 額外屬性 attr([]) 對于前端來說,后臺有部分數據是需要計算后才能獲得的,比如打卡計劃持續了多久,這個就需要時間計算,但是后端可以提前做好 `getDurationAttr` ``` let plan = new Mogo.Model("plan"); plan .where({ title: ["like", "劉"] }) .order("id asc") .with(["owner", "comment.user", "joiner", "tags"]) .attr(["duration"]) .find() .then(res => { console.log(res); }); ``` ## 鏈式調用 where,attr,order,with 都可以鏈式調用 find,findOne 后只能是then函數。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看