diff --git a/database/relations.md b/database/relations.md index 2d8ead82..e2e7c646 100644 --- a/database/relations.md +++ b/database/relations.md @@ -1176,7 +1176,18 @@ You may also specify an operator and count to further customize the query: $posts = Post::has('comments', '>=', 3)->get(); ``` -> **NOTE**: MySQL strict mode can sometimes complain when using a `GROUP` column without a `GROUP BY` clause (in the above case, `COUNT()`). You can set the `strict` option to `false` in your database's connection configuration (i.e. `database.connections.mysql.strict`) to ignore this warning message. +> **NOTE**: MySQL strict mode can sometimes complain when using a `GROUP` column without a `GROUP BY` clause (in the above case, `COUNT()`). To ignore this warning message, you can set the `strict` option to `false` in your database's connection configuration (i.e. `database.connections.mysql.strict`) or disable the `strict` option the time of running your query (see below). + +```php +// Disable mysql strict mode +config()->set('database.connections.mysql.strict', false); +DB::reconnect(); +// Retrieve all posts that have three or more comments... +$posts = Post::has('comments', '>=', 3)->get(); +// Re-enable mysql strict mode +config()->set('database.connections.mysql.strict', true); +DB::reconnect(); +``` Nested `has` statements may also be constructed using "dot" notation. For example, you may retrieve all posts that have at least one comment and vote: