久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      <i id='DEjag'><tr id='DEjag'><dt id='DEjag'><q id='DEjag'><span id='DEjag'><b id='DEjag'><form id='DEjag'><ins id='DEjag'></ins><ul id='DEjag'></ul><sub id='DEjag'></sub></form><legend id='DEjag'></legend><bdo id='DEjag'><pre id='DEjag'><center id='DEjag'></center></pre></bdo></b><th id='DEjag'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='DEjag'><tfoot id='DEjag'></tfoot><dl id='DEjag'><fieldset id='DEjag'></fieldset></dl></div>

      <tfoot id='DEjag'></tfoot>

      1. <small id='DEjag'></small><noframes id='DEjag'>

          <bdo id='DEjag'></bdo><ul id='DEjag'></ul>

        <legend id='DEjag'><style id='DEjag'><dir id='DEjag'><q id='DEjag'></q></dir></style></legend>

        帶有一些約束的 Eloquent 嵌套關(guān)系

        Eloquent Nested Relation with Some Constraint(帶有一些約束的 Eloquent 嵌套關(guān)系)

              <bdo id='CJ7RA'></bdo><ul id='CJ7RA'></ul>
            • <i id='CJ7RA'><tr id='CJ7RA'><dt id='CJ7RA'><q id='CJ7RA'><span id='CJ7RA'><b id='CJ7RA'><form id='CJ7RA'><ins id='CJ7RA'></ins><ul id='CJ7RA'></ul><sub id='CJ7RA'></sub></form><legend id='CJ7RA'></legend><bdo id='CJ7RA'><pre id='CJ7RA'><center id='CJ7RA'></center></pre></bdo></b><th id='CJ7RA'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='CJ7RA'><tfoot id='CJ7RA'></tfoot><dl id='CJ7RA'><fieldset id='CJ7RA'></fieldset></dl></div>

              • <small id='CJ7RA'></small><noframes id='CJ7RA'>

                <legend id='CJ7RA'><style id='CJ7RA'><dir id='CJ7RA'><q id='CJ7RA'></q></dir></style></legend>

                  <tfoot id='CJ7RA'></tfoot>
                    <tbody id='CJ7RA'></tbody>
                  本文介紹了帶有一些約束的 Eloquent 嵌套關(guān)系的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我有以下三個表:

                  A
                  -------------
                  | id | name |
                  -------------
                  
                  B
                  --------------------
                  | id | A_id | name |
                  --------------------
                  
                  C
                  --------------------
                  | id | B_id | name |
                  --------------------
                  

                  所以,C表的數(shù)據(jù)屬于B表的數(shù)據(jù),A表的數(shù)據(jù).現(xiàn)在,我想查詢 C,同時還從 BA 檢索數(shù)據(jù),下面的代碼可以很好地解決問題.

                  So, the data in table C belongs to the data in table B which belongs to the data in table A. Now, I want to query C, while also retrieving data from B and A and the following code does the trick just fine.

                  C::with('B.A')->get();
                  

                  現(xiàn)在的問題是,我想用一些約束來查詢 C.這些約束之一是Aid.我嘗試了以下方法:

                  The problem now, is that I want to query C with some constraints. One of these constraints is the id of A. I've tried the following:

                  C::with(array('B.A' => function ($query)
                  {
                      $query->where('id', '=', $constraint);
                  }))->get();
                  

                  但似乎 Eloquent 會檢索 C 中的所有行,甚至不考慮約束,除非它執(zhí)行查詢以檢索表 A 中的數(shù)據(jù).我該如何解決這個問題?我是否需要在 C 中添加另一個字段,即 A_id,并將 $constraint 與該字段匹配?

                  But it seems that Eloquent will retrieve all the rows in C without even taking the constraint into account, except when it's executing the query to retrieve data in table A. How do I get around this problem? Do I need to add another field in C, that is A_id, and match $constraint against that field?

                  推薦答案

                  您將 with() 方法與 SQL 的 JOIN 混淆,這種情況經(jīng)常發(fā)生.

                  You are confusing the with() method with SQL's JOIN and that happens a lot.

                  >

                  首先介紹一下背景

                  當(dāng)你使用 Foo::with('bar')->where_something(1) 時,Laravel 將首先加載 Foo 然后,基于 Foo.bar_id,它將加載Bar.它的目的是告訴 Laravel 在組合查詢上預(yù)先加載模型的依賴項,從而大大提高這些模型的迭代性能.

                  When you use Foo::with('bar')->where_something(1), Laravel will first load the Foo and then, based on Foo.bar_id, it will load the Bar. It serves the purpose of telling Laravel to eager load dependencies of your model on a combined query, greatly improving performance of iterations on those models.

                  如果你不使用它,應(yīng)該執(zhí)行以下查詢:

                  If you don't use it, the following queries should be executed:

                  SELECT * FROM foos WHERE foos.something = 1;
                  SELECT * FROM bars WHERE bars.id = 30;
                  SELECT * FROM bars WHERE bars.id = 57;
                  SELECT * FROM bars WHERE bars.id = 134;
                  SELECT * FROM bars WHERE bars.id = 1096;
                  

                  另一方面,如果你使用它:

                  If you use it, on the other hand:

                  SELECT * FROM foos WHERE foos.something = 1;
                  SELECT * FROM bars WHERE bars.id IN (30, 57, 134, 1096); // Eager loading
                  

                  當(dāng)您向 with() 添加條件時,您只會限制這些依賴項的預(yù)加載,而不是第一個查詢.

                  When you add a condition to that with(), you are only constraining the eager loading of those dependencies, and not the first query.

                  要實現(xiàn)您想要的,您需要使用 ->join().

                  To achieve what you want, you'll need to use ->join().

                  C::with(array('b', 'b.a'))
                   ->join('b', 'b.id', '=', 'c.b_id')
                   ->join('a', 'a.id', '=', 'b.a_id')
                   ->where('a.id', '=', $ID)
                   ->get('c.*');
                  

                  我已經(jīng)包含了 with(),因為我不知道您是否需要訪問 $c->b->a.如果你不這樣做,而你只需要 $c 數(shù)據(jù),你可以刪除 with() 因為它會不必要地查詢 B 和 A.

                  I've included the with(), because I didn't know if you would need to access $c->b->a. If you don't, and you just need $c data, you can remove the with() since it will query for B's and A's unnecessarily.

                  這篇關(guān)于帶有一些約束的 Eloquent 嵌套關(guān)系的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標(biāo)不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術(shù)方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅(qū)動程序)

                  <legend id='l2qUW'><style id='l2qUW'><dir id='l2qUW'><q id='l2qUW'></q></dir></style></legend>

                    <tfoot id='l2qUW'></tfoot>
                  • <i id='l2qUW'><tr id='l2qUW'><dt id='l2qUW'><q id='l2qUW'><span id='l2qUW'><b id='l2qUW'><form id='l2qUW'><ins id='l2qUW'></ins><ul id='l2qUW'></ul><sub id='l2qUW'></sub></form><legend id='l2qUW'></legend><bdo id='l2qUW'><pre id='l2qUW'><center id='l2qUW'></center></pre></bdo></b><th id='l2qUW'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='l2qUW'><tfoot id='l2qUW'></tfoot><dl id='l2qUW'><fieldset id='l2qUW'></fieldset></dl></div>

                    <small id='l2qUW'></small><noframes id='l2qUW'>

                      <tbody id='l2qUW'></tbody>

                        • <bdo id='l2qUW'></bdo><ul id='l2qUW'></ul>
                            主站蜘蛛池模板: 国产精品日韩在线 | 亚洲精品福利视频 | 黄色视频a级毛片 | 国产精品一区二区三区99 | 国产欧美一级 | 四虎影院在线免费观看 | 自拍偷拍在线视频 | 成人亚洲| 91精品国产91久久久久青草 | 国精产品一区二区三区 | 天天天天操 | 日韩中文一区二区三区 | 日韩av一区二区在线观看 | 国产福利资源 | 国内精品视频 | 在线国产一区二区三区 | 欧美在线视频一区 | 日本高清精品 | 91在线看 | 国产精品一二三区 | 日本成人免费网站 | 欧美成视频 | 国产激情视频在线观看 | 亚洲视频三区 | 久久国产精品久久久久久 | 国产精品久久久久久久久久东京 | 国产毛片久久久 | 成人九区| 91免费在线播放 | 日韩av在线不卡 | 久久精品一 | 成年人黄色免费视频 | 国产精品免费一区二区三区四区 | 草草视频在线观看 | 国产日韩一区二区 | 精品毛片在线观看 | 一区二区三区视频在线观看 | 在线免费看91 | 久热久热| 影音先锋中文字幕在线观看 | 久久不卡 |