-
wherehas 和 with的区别
2020-12-15 10:04:411.with相当于是去用关联模型去关联另一张表,另一张表中没有数据了也会将主表的数据展示出来 RoomInfo::query()->where('shop_code', $data['shop_code']) ->with(['item_arranging' => function ($query)...1.with相当于是去用关联模型去关联另一张表,另一张表中没有数据了也会将主表的数据展示出来
RoomInfo::query()->where('shop_code', $data['shop_code']) ->with(['item_arranging' => function ($query) use ($week) { $query->select('item_code', 'date', 'start_time', 'end_time', 'room_id'); }])->get();
2.wherehas是可以根据条件去筛选另一张表,另一张表中没有数据了不i会将另一张表中的数据展示出来
ItemInfo::query()->whereHas('item_arranging', function ($query) use ($week, $data) { $query->where('shop_code', $data['shop_code'])->select('item_code', 'date', 'start_time', 'end_time', 'room_id') ->with(['room_info' => function ($query) { $query->select('id', 'room_name'); }]); })->select('item_code', 'item_name') ->get();
-
"use strict" 严格模式和非严格模式的区别
2019-05-31 10:48:38严格模式和非严格模式的区别如下(前三条尤为重要) 在严格模式中禁止使用with语句(临时添加对象到作用域链的头部) 在严格模式中,所有的变量都要先声明,如果给一个未声明的变量赋值,将会抛出引用错误异常(在...ECMAScript 5中的严格模式(“use strict”)修正了语言的重要缺陷,并提供健壮的查错功能和增强的安全机制。
严格模式和非严格模式的区别如下(前三条尤为重要)- 在严格模式中禁止使用with语句(临时添加对象到作用域链的头部)
- 在严格模式中,所有的变量都要先声明,如果给一个未声明的变量赋值,将会抛出引用错误异常(在非严格模式中,将会隐式声明一个全局变量)。
- 在严格模式中,函数(不是方法,方法是赋值给对象属性的函数)中的this值是undefined。(在非严格模式中,函数中的this值总是全局对象,在浏览器中是window对象)。可以利用这种特性来判断JavaScript实现是否支持严格模式:
var hasStrictMode = (function(){"use strict"; return this === undefined})() console.log(hasStriceMode) // true支持严格模式,false不支持
注意:此处使用立即执行函数,只是为了返回结果。下面说明函数和方法的区别
// 函数 var hasStrictMode = function(){ "use strict"; return this } console.log(hasStrictMode()) // undefined // 方法 var obj = { hasStrictMode: hasStrictMode } console.log(obj.hasStrictMode()) // {hasStrictMode: f}
- 在严格模式中,当通过call()或apply()调用函数时,函数体中的this就是通过call()或apply()传入的第一个参数(在非严格模式中,null和undefined值被全局对象和转换为对象的非对象值所代替):
// 严格模式 var test = function(){ "use strict"; return this; } test.call(undefined); // undefined test.call(null); // null test.apply(undefined); // undefined test.apply(null); // null // 非严格模式 var test2 = function(){ return this; } test2.call(null); // Window {postMessage: ƒ, blur: ƒ, focus: ƒ, close: ƒ, frames: Window, …} test2.apply(undefined); // Window {postMessage: ƒ, blur: ƒ, focus: ƒ, close: ƒ, frames: Window, …}
- 在严格模式中,给只读属性赋值和给不可扩展的对象创建新成员都将抛出一个类型错误异常(在非严格模式中,这些操作只是简单地操作失败,不会报错)。
- 在严格模式中,传入eval()的代码不能在调用程序所在的上下文中声明变量或定义函数,而在非严格模式中可以(变量和函数的定义是在eval()创建的新作用域中,这个作用域在eval()返回时就会被弃用)。
- 在严格模式中,函数里的arguments对象拥有传入函数值的静态副本。在非严格模式中,arguments对象里的元素和函数参数都是指向同一个值的引用。
- 在严格模式中,delete运算符后跟随非法的标识符(比如变量、函数、函数参数)时,会抛出一个语法错误异常(在非严格模式中,这种delete表达式什么也没做,并返回false)。
- 在严格模式中,delete表达式试图删除一个不可配置的属性时将抛出一个类型错误异常(在非严格模式中,delete表达式操作失败,并返回false)。
- 在严格模式中,在一个对象直接量中定义两个或多个同名属性将产生一个语法错误(在非严格模式中不会报错)。
- 在严格模式中,函数声明中存在两个或多个同名的参数将产生一个语法错误(在非严格模式中不会报错)。
- 在严格模式中不允许使用八进制整数直接量(以0位前缀,注意不是0x为前缀)(在非严格模式中某些实现允许)。
- 在严格模式中,标识符eval和arguments是关键字,不能给它们赋值,也不能把它们声明为变量、用做函数名、用做函数参数或用做catch块的标识符。
- 在严格模式中,限制了对调用栈的检测能力。在严格模式的函数中,arguments.caller和arguments.callee都会抛出一个类型引用错误异常。严格模式的函数具有caller和arguments属性,当访问这两个属性时将会抛出类型错误异常(在非严格模式中,有一些JavaScript的实现定义了这些属性,这些属性是非标准的)。
-
【转帖】with rollup和with cube的区别
2010-11-15 08:32:00use test create table test(id int,sort char(10),color char(10),num int constraint pk_test primary key(id,sort,color)) --插入数据 insert into test select 1,'book','blue',10 union all ...--创建测试表 use test create table test(id int,sort char(10),color char(10),num int constraint pk_test primary key(id,sort,color)) --插入数据 insert into test select 1,'book','blue',10 union all select 1,'book','green',10 union all select 1,'book','red',10 union all select 1,'car','blue',10 union all select 1,'car','red',10 union all select 2,'car','red',10 --group by select sort,color,sum(num) as num from test group by sort,color --输出结果 --book blue 10 --car blue 10 --book green 10 --book red 10 --car red 20 --group by with rollup select case when grouping(sort)=1 then 'all' else isnull(sort,'unknow') end as sort, case when grouping(color)=1 then 'all' else isnull(color,'unknow') end as color, sum(num) as num from test group by sort,color with rollup --输出结果 --book blue 10 --book green 10 --book red 10 --book all 30 --car blue 10 --car red 20 --car all 30 --all all 60 --group by with cube select case when grouping(sort)=1 then 'all' else isnull(sort,'unknow') end as sort, case when grouping(color)=1 then 'all' else isnull(color,'unknow') end as color, sum(num) as num from test group by sort,color with cube --输出结果 --book blue 10 --book green 10 --book red 10 --book all 30 --car blue 10 --car red 20 --car all 30 --all all 60 --all blue 20 --all green 10 --all red 30 总结: 1、CUBE 和 ROLLUP区别: ? CUBE 生成的结果集显示了所选列中值的所有组合的聚合。 ? ROLLUP 生成的结果集显示了所选列中值的某一层次结构的聚合。 2、GROUPING是一个聚合函数,它产生一个附加的列,当用 CUBE 或 ROLLUP 运算符添加行时,附加的列输出值为1,当所添加的行不是由 CUBE 或 ROLLUP 产生时,附加列值为0。 仅在与包含 CUBE 或 ROLLUP 运算符的 GROUP BY 子句相联系的选择列表中才允许分组。
-
Laravel关联模型中过滤结果为空的结果集(has和with区别)
2020-12-18 05:14:27$userCoupons = UserCoupons::with(['coupon' => function($query) use($groupId){ return $query->select('id', 'group_id', 'cover', 'group_number', 'group_cover')->where([ 'group_id' => $groupId, ]); }]... -
Laravel ORM中with,wherehas使用和区别
2021-04-08 11:00:09Laravel ORM中with,wherehas使用和区别 with -预加载 当作为属性访问 Eloquent 关联时,关联数据是「懒加载」的。意味着在你第一次访问该属性时,才会加载关联数据。不过,是当你查询父模型时,Eloquent 可以「预...Laravel ORM中with,wherehas使用和区别
with -预加载
当作为属性访问 Eloquent 关联时,关联数据是「懒加载」的。意味着在你第一次访问该属性时,才会加载关联数据。不过,是当你查询父模型时,Eloquent 可以「预加载」关联数据。预加载避免了 N + 1 查询问题。要说明 N + 1 查询问题,试想一个 Book 模型关联到 Author 模型:
<?php namespace App; use Illuminate\Database\Eloquent\Model; class Book extends Model { /** * 获得此书的作者。 */ public function author() { return $this->belongsTo('App\Author'); } }
现在,让我们来获得所有书籍和作者数据:
$books = App\Book::all(); foreach ($books as $book) { echo $book->author->name; }
这个循环会运行一次查询取回所有数据表上的书籍数据,然后又运行一次查询获得每本书的作者数据。如果我们有 25 本书,则循环就会执行 26 次查询:1 次是获得所有书籍数据,另外 25 条查询用来获得每本书的作者数据。
谢天谢地,我们使用预加载让整个查询减少到 2 次。这是通过指定关联给 with 方法办到的:
$books = App\Book::with('author')->get(); foreach ($books as $book) { echo $book->author->name; }
整个操作,只执行了两条查询:
select * from books select * from authors where id in (1, 2, 3, 4, 5, ...)
基于存在的关联查询 has wherehas
如果您需要更高级的用法,可以使用 whereHas 和 orWhereHas 方法在 has 查询里设置「where」条件。此方法可以让你增加自定义条件至关联约束中,例如对评论内容进行检查:
// 获得所有至少有一条评论内容满足 foo% 条件的文章 $posts = Post::whereHas('comments', function ($query) { $query->where('content', 'like', 'foo%'); })->get();
用法
with([‘关联关系:id,name’])
whereHas(‘关联关系’, function ($query){})区别
with – 类似于 SQL 中的 left join。
has – 类似于 SQL 中的 inner join。
whereHas – 是has的补充,可以补充查询条件 -
WINAPI和CALLBACK的区别
2019-10-01 02:41:56WINAPI和CALLBACK的区别[转] _stdcall _cdecl _pascal _fastcall这些关键字是什么意思,有什么区别呢? 首先看MSDN里给出的解释,不过有些语焉不详哦WINAPI ·Use in place of FAR PASCAL in API declarations. If ... -
-
No default session is registered. Use `with sess.as_default()` 报错的解决
2020-02-12 19:51:12今天出现了这个报错,具体的解决方法, 将sess = tf.Session()改为sess = tf.InteractiveSession...出现这种情况好像是因为Session.run()和Tensor.eval()两者之间有一定的区别,sess.run()在同一步获取多个tensor... -
严格模式和普通模式的区别
2020-07-22 11:43:34严格模式和普通模式有以下几种区别 变量声明 禁止使用with 设立eval作用域 函数中的this指向问题 删除变量 函数参数不能重名 八进制字面量表示法 arguments不追踪参数变化 变量声明 注意 -
Vim 和 emacs的区别
2014-02-11 07:47:08With Emacs you are expected to have it open 24/7 and live inside the program, almost everything you do can be done from there. You write your own extensions, use it for note taking, organisation -
Python中Mock和MagicMock的区别
2017-03-18 12:27:08Python的unittest.mock模块中提供了两个主要的mock类,分别是Mock和MagicMock. ...MagicMock is a subclass of Mock with all the magic methods pre-created and ready to use. 其实已经很清楚了,Mag... -
PendingIntent和Intent的区别
2012-04-18 17:51:00An Intent is something that is used right now; a PendingIntent is something that may create an Intent in the future. You will use a PendingIntent with Notifications, AlarmManager, etc. Notification... -
接口的golang地址和接口的区别
2018-08-28 15:19:11<pre><code>Cannot use '&w' (type *http.ResponseWriter) as type ResponseWriter </code></pre> <p>I wonder why <code>buf</code> have '&' can works, but another don't work? <p>I googled, ... -
new和override的区别
2012-03-19 21:22:00It is an error to use both new and override on the same member because the two modifiers have mutually exclusive meanings.The new modifiers creates a new member with the same name and caus... -
python mock_Python中Mock和MagicMock的区别
2020-12-03 08:26:08先看一下官方文档的定义:MagicMock is a subclass of Mock with all the magic methods pre-created and ready to use.其实已经很清楚了,MagicMock是Mock的子类,并且预先创建了全部magic met... -
CompletableFuture join和get方法的区别
2019-11-05 20:41:05join方法 /** * Returns the result value when complete, or throws an * (unchecked) exception if completed exceptionally.... * conform with the use of common functional forms, if a ... -
AppCompatActivity类和activity类的区别
2020-09-07 17:09:20AppcompaActivity相对于Activity的主要的两点变化; 1:主界面带有toolbar的... 否则会提示错误: Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this -
goroutine和线程之间的区别
2017-10-26 02:15:18<p>I'm a newbie on Golang and I just learnt about the conception Goroutine with an example below: </p> <pre><code>package main import "fmt" func f(from string) { for i := 0; i < 3; i++ { ... -
varchar 和varchar2 的区别
2013-09-29 11:46:33Do not use the VARCHAR data type. Use the VARCHAR2 data type instead. Although the ... type is currently synonymous with VARCHAR2, the VARCHAR data type is scheduled to be redefined as -
NSNotification、delegate和KVO的区别
2014-07-28 08:35:52KVO vs NSNotification vs protocol/delegate: ...1. Use a delegate if you want to talk to only one object. For example, a tableView has a delegate - only one object should be responsible for dealing with -
InDelta和InEpsilon之间的区别
2017-07-25 17:46:13return Fail(t, fmt.Sprintf("Expected %v with delta %v, but was NaN", expected, delta), msgAndArgs...) } dt := af - bf if dt < -delta || dt > delta { return Fail(t, fmt.Sprintf("Max ... -
【转载】tkinter中update和updateidletasks的区别
2019-05-02 20:53:11Events scheduled with after, mostly. And, as you also mentioned in your question, events that trigger a redraw. The circumstances when you should use update over update_idleta... -
Pandas中map,applymap和apply方法之间的区别
2020-05-29 09:00:00Can you tell me when to use these vectorization methods with basic examples? 你能告诉我什么时候使用这些矢量化方法和基本的 -
JS在严格模式和非严格模式的区别
2019-01-21 20:41:00若想在严格模式下使用JS,需要在文件的第一行加上“use strict”,在实际开发中,常常将“use strict”加入到闭包的内部 具体是: 整个脚本中使用:在这个JavaScript文件开头写'use strict'; 在闭包内部中... -
HTTP中的GET和POST之间的区别[重复]
2018-12-19 05:11:48<p>I can use GET to send and get data from the server using this VBScript example: <pre><code>Send "https://www.server.com/send.php" Sub Send(url) Dim objHTTP, MyResponse Set objHTTP = CreateObject...