From 5adf533b87f4edb5fd2a2c95edd02a08d0250d4b Mon Sep 17 00:00:00 2001 From: Mike Fellows Date: Fri, 21 Apr 2017 14:53:00 -0400 Subject: [PATCH] Fix findTagged "no tags" query in bookmarks tutorial. - There is a bug in the exising findTagged function. When calling the function without any tags specified all bookmarks are returned, rather than the bookmarks that have no associated tags. - The alternative query (tags specified) was also adjusted to use a similar approach - specifying the conditional after the join, rather than in it, IMHO making the logic a little clearer. --- en/tutorials-and-examples/bookmarks/intro.rst | 12 +++++----- es/tutorials-and-examples/bookmarks/intro.rst | 12 +++++----- fr/tutorials-and-examples/bookmarks/intro.rst | 12 +++++----- ja/tutorials-and-examples/bookmarks/intro.rst | 12 +++++----- pt/tutorials-and-examples/bookmarks/intro.rst | 12 +++++----- ru/tutorials-and-examples/bookmarks/intro.rst | 12 +++++----- tr/tutorials-and-examples/bookmarks/intro.rst | 22 ++++++++++++------- 7 files changed, 50 insertions(+), 44 deletions(-) diff --git a/en/tutorials-and-examples/bookmarks/intro.rst b/en/tutorials-and-examples/bookmarks/intro.rst index c73fcf478f..7f14c6dd48 100644 --- a/en/tutorials-and-examples/bookmarks/intro.rst +++ b/en/tutorials-and-examples/bookmarks/intro.rst @@ -362,13 +362,13 @@ method has not been implemented yet, so let's do that. In ->select(['id', 'url', 'title', 'description']); if (empty($options['tags'])) { - $bookmarks->leftJoinWith('Tags', function ($q) { - return $q->where(['Tags.title IS ' => null]); - }); + $bookmarks + ->leftJoinWith('Tags') + ->where(['Tags.title IS' => null]); } else { - $bookmarks->innerJoinWith('Tags', function ($q) use ($options) { - return $q->where(['Tags.title IN' => $options['tags']]); - }); + $bookmarks + ->innerJoinWith('Tags') + ->where(['Tags.title IN ' => $options['tags']]); } return $bookmarks->group(['Bookmarks.id']); diff --git a/es/tutorials-and-examples/bookmarks/intro.rst b/es/tutorials-and-examples/bookmarks/intro.rst index 9e44a4355b..9a27186121 100644 --- a/es/tutorials-and-examples/bookmarks/intro.rst +++ b/es/tutorials-and-examples/bookmarks/intro.rst @@ -325,13 +325,13 @@ En **src/Model/Table/BookmarksTable.php** añade lo siguiente:: ->select(['id', 'url', 'title', 'description']); if (empty($options['tags'])) { - $bookmarks->leftJoinWith('Tags', function ($q) { - return $q->where(['Tags.title IS ' => null]); - }); + $bookmarks + ->leftJoinWith('Tags') + ->where(['Tags.title IS' => null]); } else { - $bookmarks->innerJoinWith('Tags', function ($q) use ($options) { - return $q->where(['Tags.title IN' => $options['tags']]); - }); + $bookmarks + ->innerJoinWith('Tags') + ->where(['Tags.title IN ' => $options['tags']]); } return $bookmarks->group(['Bookmarks.id']); diff --git a/fr/tutorials-and-examples/bookmarks/intro.rst b/fr/tutorials-and-examples/bookmarks/intro.rst index bc702f45f9..0f6f97b4f8 100644 --- a/fr/tutorials-and-examples/bookmarks/intro.rst +++ b/fr/tutorials-and-examples/bookmarks/intro.rst @@ -383,13 +383,13 @@ Dans **src/Model/Table/BookmarksTable.php** ajoutez ce qui suit:: ->select(['id', 'url', 'title', 'description']); if (empty($options['tags'])) { - $bookmarks->leftJoinWith('Tags', function ($q) { - return $q->where(['Tags.title IS ' => null]); - }); + $bookmarks + ->leftJoinWith('Tags') + ->where(['Tags.title IS' => null]); } else { - $bookmarks->innerJoinWith('Tags', function ($q) use ($options) { - return $q->where(['Tags.title IN' => $options['tags']]); - }); + $bookmarks + ->innerJoinWith('Tags') + ->where(['Tags.title IN ' => $options['tags']]); } return $bookmarks->group(['Bookmarks.id']); diff --git a/ja/tutorials-and-examples/bookmarks/intro.rst b/ja/tutorials-and-examples/bookmarks/intro.rst index bdbae677f3..a9938a3d37 100644 --- a/ja/tutorials-and-examples/bookmarks/intro.rst +++ b/ja/tutorials-and-examples/bookmarks/intro.rst @@ -349,13 +349,13 @@ CakePHP では、コントローラのアクションをスリムに保ち、ア ->select(['id', 'url', 'title', 'description']); if (empty($options['tags'])) { - $bookmarks->leftJoinWith('Tags', function ($q) { - return $q->where(['Tags.title IS ' => null]); - }); + $bookmarks + ->leftJoinWith('Tags') + ->where(['Tags.title IS' => null]); } else { - $bookmarks->innerJoinWith('Tags', function ($q) use ($options) { - return $q->where(['Tags.title IN' => $options['tags']]); - }); + $bookmarks + ->innerJoinWith('Tags') + ->where(['Tags.title IN ' => $options['tags']]); } return $bookmarks->group(['Bookmarks.id']); diff --git a/pt/tutorials-and-examples/bookmarks/intro.rst b/pt/tutorials-and-examples/bookmarks/intro.rst index 651d0167a5..1d6a7d2155 100644 --- a/pt/tutorials-and-examples/bookmarks/intro.rst +++ b/pt/tutorials-and-examples/bookmarks/intro.rst @@ -296,13 +296,13 @@ método ``findTagged`` não estar implementado ainda, então vamos fazer isso. E ->select(['id', 'url', 'title', 'description']); if (empty($options['tags'])) { - $bookmarks->leftJoinWith('Tags', function ($q) { - return $q->where(['Tags.title IS ' => null]); - }); + $bookmarks + ->leftJoinWith('Tags') + ->where(['Tags.title IS' => null]); } else { - $bookmarks->innerJoinWith('Tags', function ($q) use ($options) { - return $q->where(['Tags.title IN' => $options['tags']]); - }); + $bookmarks + ->innerJoinWith('Tags') + ->where(['Tags.title IN ' => $options['tags']]); } return $bookmarks->group(['Bookmarks.id']); diff --git a/ru/tutorials-and-examples/bookmarks/intro.rst b/ru/tutorials-and-examples/bookmarks/intro.rst index d195e12404..ec1bd1b990 100644 --- a/ru/tutorials-and-examples/bookmarks/intro.rst +++ b/ru/tutorials-and-examples/bookmarks/intro.rst @@ -364,13 +364,13 @@ CakePHP мы разделяем методы, оперирующие с колл ->select(['id', 'url', 'title', 'description']); if (empty($options['tags'])) { - $bookmarks->leftJoinWith('Tags', function ($q) { - return $q->where(['Tags.title IS ' => null]); - }); + $bookmarks + ->leftJoinWith('Tags') + ->where(['Tags.title IS' => null]); } else { - $bookmarks->innerJoinWith('Tags', function ($q) use ($options) { - return $q->where(['Tags.title IN' => $options['tags']]); - }); + $bookmarks + ->innerJoinWith('Tags') + ->where(['Tags.title IN ' => $options['tags']]); } return $bookmarks->group(['Bookmarks.id']); diff --git a/tr/tutorials-and-examples/bookmarks/intro.rst b/tr/tutorials-and-examples/bookmarks/intro.rst index 7c11780f34..8f0d37022c 100644 --- a/tr/tutorials-and-examples/bookmarks/intro.rst +++ b/tr/tutorials-and-examples/bookmarks/intro.rst @@ -349,14 +349,20 @@ de şunları ekleyiniz:: // 'tags' seçeneğini içerir. public function findTagged(Query $query, array $options) { - return $this->find() - ->distinct(['Bookmarks.id']) - ->matching('Tags', function ($q) use ($options) { - if (empty($options['tags'])) { - return $q->where(['Tags.title IS' => null]); - } - return $q->where(['Tags.title IN' => $options['tags']]); - }); + $bookmarks = $this->find() + ->select(['id', 'url', 'title', 'description']); + + if (empty($options['tags'])) { + $bookmarks + ->leftJoinWith('Tags') + ->where(['Tags.title IS' => null]); + } else { + $bookmarks + ->innerJoinWith('Tags') + ->where(['Tags.title IN ' => $options['tags']]); + } + + return $bookmarks->group(['Bookmarks.id']); } Biz :ref:`özel bulucu metodu ` geliştirdik. Bu CakePHP nin