[BUGFIX] Queries don't respect MM_match_fields 13/29713/11
authorStefan Froemken <froemken@gmail.com>
Mon, 28 Apr 2014 17:18:44 +0000 (19:18 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 3 May 2014 13:05:38 +0000 (15:05 +0200)
In case of sys_category and all other
MM-relations with MM_match_fields, parseConstraint
has no implementation for this property.

This patch adds MM_match_fields for
matching and deletion.

Resolves: #10487
Releases: 6.2
Change-Id: Id4f53fd4ed42dd6e785011b5efbc61f6ce62e022
Reviewed-on: https://review.typo3.org/29713
Reviewed-by: Fabien Udriot
Tested-by: Fabien Udriot
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php
typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbQueryParser.php
typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Classes/Domain/Model/Post.php
typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Classes/Domain/Repository/PostRepository.php
typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/ext_tables.php
typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/categories.xml [new file with mode: 0644]
typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/category-mm.xml [new file with mode: 0644]
typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/post-tag-mm.xml
typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/posts.xml
typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/tags.xml
typo3/sysext/extbase/Tests/Functional/Persistence/RelationTest.php

index 539a022..4838368 100644 (file)
@@ -556,7 +556,7 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
                                $row[$parentTableFieldName] = $parentDataMap->getTableName();
                        }
                        $relationTableMatchFields = $parentColumnMap->getRelationTableMatchFields();
-                       if (is_array($relationTableMatchFields) && count($relationTableMatchFields)) {
+                       if (is_array($relationTableMatchFields)) {
                                $row = array_merge($relationTableMatchFields, $row);
                        }
                }
@@ -631,7 +631,7 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
                if ($parentObject !== NULL && $parentPropertyName) {
                        $parentColumnDataMap = $this->dataMapper->getDataMap(get_class($parentObject))->getColumnMap($parentPropertyName);
                        $relationTableMatchFields = $parentColumnDataMap->getRelationTableMatchFields();
-                       if (is_array($relationTableMatchFields) && count($relationTableMatchFields) > 0) {
+                       if (is_array($relationTableMatchFields)) {
                                $row = array_merge($relationTableMatchFields, $row);
                        }
                        if ($parentColumnDataMap->getParentKeyFieldName() !== NULL) {
@@ -678,25 +678,16 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
                        $columnMap->getChildSortByFieldName() => !is_null($sortingPosition) ? (int)$sortingPosition : 0
                );
                $relationTableName = $columnMap->getRelationTableName();
-               // FIXME Reenable support for tablenames
-               // $childTableName = $columnMap->getChildTableName();
-               // if (isset($childTableName)) {
-               //      $row['tablenames'] = $childTableName;
-               // }
                if ($columnMap->getRelationTablePageIdColumnName() !== NULL) {
                        $row[$columnMap->getRelationTablePageIdColumnName()] = $this->determineStoragePageIdForNewRecord();
                }
                $relationTableMatchFields = $columnMap->getRelationTableMatchFields();
-               if (count($relationTableMatchFields)) {
-                       foreach ($relationTableMatchFields as $matchField => $matchValue) {
-                               $row[$matchField] = $matchValue;
-                       }
+               if (is_array($relationTableMatchFields)) {
+                       $row = array_merge($relationTableMatchFields, $row);
                }
                $relationTableInsertFields = $columnMap->getRelationTableInsertFields();
-               if (count($relationTableInsertFields)) {
-                       foreach ($relationTableInsertFields as $insertField => $insertValue) {
-                               $row[$insertField] = $insertValue;
-                       }
+               if (is_array($relationTableInsertFields)) {
+                       $row = array_merge($relationTableInsertFields, $row);
                }
                $res = $this->storageBackend->addRow($relationTableName, $row, TRUE);
                return $res;
@@ -720,14 +711,8 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
                        $columnMap->getChildSortByFieldName() => (int)$sortingPosition
                );
                $relationTableName = $columnMap->getRelationTableName();
-               // FIXME Reenable support for tablenames
-               // $childTableName = $columnMap->getChildTableName();
-               // if (isset($childTableName)) {
-               //      $row['tablenames'] = $childTableName;
-               // }
-
                $relationTableMatchFields = $columnMap->getRelationTableMatchFields();
-               if (is_array($relationTableMatchFields) && count($relationTableMatchFields) > 0) {
+               if (is_array($relationTableMatchFields)) {
                        $row = array_merge($relationTableMatchFields, $row);
                }
                $res = $this->storageBackend->updateRelationTableRow(
@@ -751,7 +736,7 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
                        $columnMap->getParentKeyFieldName() => (int)$parentObject->getUid()
                );
                $relationTableMatchFields = $columnMap->getRelationTableMatchFields();
-               if (is_array($relationTableMatchFields) && count($relationTableMatchFields) > 0) {
+               if (is_array($relationTableMatchFields)) {
                        $relationMatchFields = array_merge($relationTableMatchFields, $relationMatchFields);
                }
                $res = $this->storageBackend->removeRow($relationTableName, $relationMatchFields, FALSE);
@@ -770,10 +755,15 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
                $dataMap = $this->dataMapper->getDataMap(get_class($parentObject));
                $columnMap = $dataMap->getColumnMap($parentPropertyName);
                $relationTableName = $columnMap->getRelationTableName();
-               $res = $this->storageBackend->removeRow($relationTableName, array(
+               $relationMatchFields = array(
                        $columnMap->getParentKeyFieldName() => (int)$parentObject->getUid(),
                        $columnMap->getChildKeyFieldName() => (int)$relatedObject->getUid()
-               ), FALSE);
+               );
+               $relationTableMatchFields = $columnMap->getRelationTableMatchFields();
+               if (is_array($relationTableMatchFields)) {
+                       $relationMatchFields = array_merge($relationTableMatchFields, $relationMatchFields);
+               }
+               $res = $this->storageBackend->removeRow($relationTableName, $relationMatchFields, FALSE);
                return $res;
        }
 
@@ -817,7 +807,7 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
                        );
 
                        $relationTableMatchFields = $parentColumnMap->getRelationTableMatchFields();
-                       if (is_array($relationTableMatchFields) && count($relationTableMatchFields) > 0) {
+                       if (is_array($relationTableMatchFields)) {
                                $matchFields = array_merge($relationTableMatchFields, $matchFields);
                        }
                } else {
index ac64515..eed164d 100644 (file)
@@ -367,7 +367,17 @@ class Typo3DbQueryParser implements \TYPO3\CMS\Core\SingletonInterface {
                                $typeOfRelation = $columnMap instanceof ColumnMap ? $columnMap->getTypeOfRelation() : NULL;
                                if ($typeOfRelation === ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
                                        $relationTableName = $columnMap->getRelationTableName();
-                                       $sql['where'][] = $tableName . '.uid IN (SELECT ' . $columnMap->getParentKeyFieldName() . ' FROM ' . $relationTableName . ' WHERE ' . $columnMap->getChildKeyFieldName() . '=' . $parameterIdentifier . ')';
+                                       $relationTableMatchFields = $columnMap->getRelationTableMatchFields();
+                                       if (is_array($relationTableMatchFields)) {
+                                               $additionalWhere = array();
+                                               foreach ($relationTableMatchFields as $fieldName => $value) {
+                                                       $additionalWhere[] = $fieldName . ' = ' . $this->databaseHandle->fullQuoteStr($value, $relationTableName);
+                                               }
+                                               $additionalWhereForMatchFields = ' AND ' . implode(' AND ', $additionalWhere);
+                                       } else {
+                                               $additionalWhereForMatchFields = '';
+                                       }
+                                       $sql['where'][] = $tableName . '.uid IN (SELECT ' . $columnMap->getParentKeyFieldName() . ' FROM ' . $relationTableName . ' WHERE ' . $columnMap->getChildKeyFieldName() . '=' . $parameterIdentifier . $additionalWhereForMatchFields . ')';
                                } elseif ($typeOfRelation === ColumnMap::RELATION_HAS_MANY) {
                                        $parentKeyFieldName = $columnMap->getParentKeyFieldName();
                                        if (isset($parentKeyFieldName)) {
index ccf1274..004ad1d 100644 (file)
@@ -62,6 +62,11 @@ class Post extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
        protected $tags = NULL;
 
        /**
+        * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\Category>
+        */
+       protected $categories = NULL;
+
+       /**
         * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\ExtbaseTeam\BlogExample\Domain\Model\Comment>
         * @lazy
         * @cascade remove
@@ -79,6 +84,7 @@ class Post extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
         */
        public function __construct() {
                $this->tags = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $this->categories = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
                $this->comments = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
                $this->relatedPosts = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
                $this->date = new \DateTime();
@@ -192,6 +198,42 @@ class Post extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
        }
 
        /**
+        * Add category to a post
+        *
+        * @param \TYPO3\CMS\Extbase\Domain\Model\Category $category
+        */
+       public function addCategory(\TYPO3\CMS\Extbase\Domain\Model\Category $category) {
+               $this->categories->attach($category);
+       }
+
+       /**
+        * Set categories
+        *
+        * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $categories
+        */
+       public function setCategories($categories) {
+               $this->categories = $categories;
+       }
+
+       /**
+        * Get categories
+        *
+        * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
+        */
+       public function getCategories() {
+               return $this->categories;
+       }
+
+       /**
+        * Remove category from post
+        *
+        * @param \TYPO3\CMS\Extbase\Domain\Model\Category $category
+        */
+       public function removeCategory(\TYPO3\CMS\Extbase\Domain\Model\Category $category) {
+               $this->categories->detach($category);
+       }
+
+       /**
         * Sets the author for this post
         *
         * @param \ExtbaseTeam\BlogExample\Domain\Model\Person $author
index de192c5..88164b4 100644 (file)
@@ -135,5 +135,20 @@ class PostRepository extends \TYPO3\CMS\Extbase\Persistence\Repository {
                        ->execute();
        }
 
+       /**
+        * Find posts by category
+        *
+        * @param int $categoryUid
+        * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
+        */
+       public function findByCategory($categoryUid) {
+               $query = $this->createQuery();
+               return $query
+                       ->matching(
+                               $query->contains('categories', $categoryUid)
+                       )
+                       ->execute();
+       }
+
 }
 ?>
\ No newline at end of file
index 0df4283..b8df354 100644 (file)
@@ -115,4 +115,7 @@ if (is_array($TCA['fe_users']['columns']['tx_extbase_type'])) {
        $TCA['fe_users']['types']['Tx_BlogExample_Domain_Model_Administrator'] = $TCA['fe_users']['types']['0'];
        array_push($TCA['fe_users']['columns']['tx_extbase_type']['config']['items'], array('LLL:EXT:blog_example/Resources/Private/Language/locallang_db.xml:fe_users.tx_extbase_type.Tx_BlogExample_Domain_Model_Administrator', 'Tx_BlogExample_Domain_Model_Administrator'));
 }
+
+// Categorize Post records
+\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::makeCategorizable($_EXTKEY, 'tx_blogexample_domain_model_post');
 ?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/categories.xml b/typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/categories.xml
new file mode 100644 (file)
index 0000000..86b109d
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<dataset>
+       <sys_category>
+               <uid>1</uid>
+               <pid>0</pid>
+               <title>Category 1</title>
+               <deleted>0</deleted>
+       </sys_category>
+       <sys_category>
+               <uid>2</uid>
+               <pid>0</pid>
+               <title>Category 2</title>
+               <deleted>0</deleted>
+       </sys_category>
+       <sys_category>
+               <uid>3</uid>
+               <pid>0</pid>
+               <title>Category 3</title>
+               <deleted>0</deleted>
+       </sys_category>
+       <sys_category>
+               <uid>4</uid>
+               <pid>0</pid>
+               <title>Category 4</title>
+               <deleted>0</deleted>
+       </sys_category>
+</dataset>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/category-mm.xml b/typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/category-mm.xml
new file mode 100644 (file)
index 0000000..debd04a
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<dataset>
+       <!-- post 1 gets categories 1,2,3 -->
+       <sys_category_record_mm>
+               <uid_local>1</uid_local>
+               <uid_foreign>1</uid_foreign>
+               <tablenames>tx_blogexample_domain_model_post</tablenames>
+               <fieldname>categories</fieldname>
+               <sorting>1</sorting>
+               <sorting_foreign>2</sorting_foreign>
+       </sys_category_record_mm>
+       <sys_category_record_mm>
+               <uid_local>2</uid_local>
+               <uid_foreign>1</uid_foreign>
+               <tablenames>tx_blogexample_domain_model_post</tablenames>
+               <fieldname>categories</fieldname>
+               <sorting>1</sorting>
+               <sorting_foreign>2</sorting_foreign>
+       </sys_category_record_mm>
+       <sys_category_record_mm>
+               <uid_local>3</uid_local>
+               <uid_foreign>1</uid_foreign>
+               <tablenames>tx_blogexample_domain_model_post</tablenames>
+               <fieldname>categories</fieldname>
+               <sorting>1</sorting>
+               <sorting_foreign>2</sorting_foreign>
+       </sys_category_record_mm>
+
+       <!-- post 2 gets category 1 -->
+       <sys_category_record_mm>
+               <uid_local>1</uid_local>
+               <uid_foreign>2</uid_foreign>
+               <tablenames>tx_blogexample_domain_model_post</tablenames>
+               <fieldname>categories</fieldname>
+               <sorting>1</sorting>
+               <sorting_foreign>2</sorting_foreign>
+       </sys_category_record_mm>
+
+       <!-- some bogus records to test MM_match_fields -->
+       <sys_category_record_mm>
+               <uid_local>4</uid_local>
+               <uid_foreign>1</uid_foreign>
+               <tablenames>tx_my_extension</tablenames>
+               <fieldname>categories</fieldname>
+               <sorting>1</sorting>
+               <sorting_foreign>2</sorting_foreign>
+       </sys_category_record_mm>
+</dataset>
index fa85b38..128edfe 100644 (file)
                <sorting_foreign>2</sorting_foreign>
        </tx_blogexample_post_tag_mm>
        <tx_blogexample_post_tag_mm>
+               <uid_local>2</uid_local>
+               <uid_foreign>11</uid_foreign>
+               <sorting>2</sorting>
+               <sorting_foreign>1</sorting_foreign>
+       </tx_blogexample_post_tag_mm>
+       <tx_blogexample_post_tag_mm>
                <uid_local>3</uid_local>
                <uid_foreign>1</uid_foreign>
                <sorting>1</sorting>
index b00872a..21ab360 100644 (file)
@@ -6,6 +6,7 @@
                <tstamp>121319</tstamp>
                <blog>1</blog>
                <tags>10</tags>
+               <categories>3</categories>
                <title>Post1</title>
                <sorting>1</sorting>
                <deleted>0</deleted>
@@ -15,6 +16,7 @@
                <pid>0</pid>
                <blog>1</blog>
                <tags>1</tags>
+               <categories>0</categories>
                <title>Post2</title>
                <sorting>2</sorting>
                <deleted>0</deleted>
@@ -24,6 +26,7 @@
                <pid>0</pid>
                <blog>1</blog>
                <tags>1</tags>
+               <categories>0</categories>
                <title>Post3</title>
                <sorting>3</sorting>
                <deleted>0</deleted>
@@ -33,6 +36,7 @@
                <pid>0</pid>
                <blog>1</blog>
                <tags>1</tags>
+               <categories>0</categories>
                <title>Post4</title>
                <sorting>4</sorting>
                <deleted>0</deleted>
@@ -42,6 +46,7 @@
                <pid>0</pid>
                <blog>1</blog>
                <tags>1</tags>
+               <categories>0</categories>
                <title>Post5</title>
                <sorting>5</sorting>
                <deleted>0</deleted>
@@ -51,6 +56,7 @@
                <pid>0</pid>
                <blog>1</blog>
                <tags>1</tags>
+               <categories>0</categories>
                <title>Post6</title>
                <sorting>6</sorting>
                <deleted>0</deleted>
@@ -60,6 +66,7 @@
                <pid>0</pid>
                <blog>1</blog>
                <tags>1</tags>
+               <categories>0</categories>
                <title>Post7</title>
                <sorting>7</sorting>
                <deleted>0</deleted>
@@ -69,6 +76,7 @@
                <pid>0</pid>
                <blog>1</blog>
                <tags>1</tags>
+               <categories>0</categories>
                <title>Post8</title>
                <sorting>8</sorting>
                <deleted>0</deleted>
@@ -78,6 +86,7 @@
                <pid>0</pid>
                <blog>1</blog>
                <tags>1</tags>
+               <categories>0</categories>
                <title>Post9</title>
                <sorting>9</sorting>
                <deleted>0</deleted>
@@ -87,6 +96,7 @@
                <pid>0</pid>
                <blog>1</blog>
                <tags>1</tags>
+               <categories>0</categories>
                <title>Post10</title>
                <sorting>10</sorting>
                <deleted>0</deleted>
                <pid>0</pid>
                <blog>2</blog>
                <tags>0</tags>
+               <categories>0</categories>
                <title>post1</title>
                <sorting>11</sorting>
                <deleted>0</deleted>
index e7af7ac..82436c1 100644 (file)
@@ -10,7 +10,7 @@
        <tx_blogexample_domain_model_tag>
                <uid>2</uid>
                <pid>0</pid>
-               <posts>1</posts>
+               <posts>2</posts>
                <name>Tag2</name>
                <deleted>0</deleted>
        </tx_blogexample_domain_model_tag>
index b20e178..ba1bec1 100644 (file)
@@ -64,6 +64,8 @@ class RelationTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
                $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/posts.xml');
                $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/tags.xml');
                $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/post-tag-mm.xml');
+               $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/categories.xml');
+               $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/category-mm.xml');
 
                $this->objectManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
                $this->persistentManager = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager');
@@ -433,6 +435,72 @@ class RelationTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
        }
 
        /**
+        * Test query matching for mm relation without MM_match_fields defined
+        *
+        * @test
+        */
+       public function MmRelationWithoutMatchFieldIsResolved() {
+               /** @var \ExtbaseTeam\BlogExample\Domain\Repository\PostRepository $postRepository */
+               $postRepository = $this->objectManager->get('ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
+               $posts = $postRepository->findByTagAndBlog('Tag2', $this->blog);
+               $this->assertSame(1, count($posts));
+       }
+
+       /**
+        * @test
+        */
+       public function MmRelationWithMatchFieldIsResolvedFromLocalSide() {
+               $countCategories = $this->getDatabaseConnection()->exec_SELECTcountRows('*', 'sys_category_record_mm', 'uid_foreign=1 AND tablenames="tx_blogexample_domain_model_post" AND fieldname="categories"');
+               $this->assertSame(3, $countCategories);
+
+               /** @var \ExtbaseTeam\BlogExample\Domain\Repository\PostRepository $postRepository */
+               $postRepository = $this->objectManager->get('ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
+               $post = $postRepository->findByUid(1);
+               $this->assertSame(3, count($post->getCategories()));
+       }
+
+       /**
+        * Test query matching respects MM_match_fields
+        *
+        * @test
+        */
+       public function MmRelationWithMatchFieldIsResolvedFromForeignSide() {
+               /** @var \ExtbaseTeam\BlogExample\Domain\Repository\PostRepository $postRepository */
+               $postRepository = $this->objectManager->get('ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
+               $posts = $postRepository->findByCategory(1);
+               $this->assertSame(2, count($posts));
+
+               $posts = $postRepository->findByCategory(4);
+               $this->assertSame(0, count($posts));
+       }
+
+       /**
+        * @test
+        */
+       public function MmRelationWithMatchFieldIsCreatedFromLocalSide() {
+               $countCategories = $this->getDatabaseConnection()->exec_SELECTcountRows('*', 'sys_category_record_mm', 'uid_foreign=1 AND tablenames="tx_blogexample_domain_model_post" AND fieldname="categories"');
+               $this->assertSame(3, $countCategories);
+
+               $postRepository = $this->objectManager->get('ExtbaseTeam\\BlogExample\\Domain\\Repository\\PostRepository');
+               $post = $postRepository->findByUid(1);
+
+               $newCategory = $this->objectManager->get('\\TYPO3\\CMS\\Extbase\\Domain\\Model\\Category');
+               $newCategory->setTitle('New Category');
+
+               $post->addCategory($newCategory);
+
+               $postRepository->update($post);
+               $this->persistentManager->persistAll();
+
+               $countCategories = $this->getDatabaseConnection()->exec_SELECTcountRows(
+                       '*',
+                       'sys_category_record_mm',
+                       'uid_foreign=1 AND tablenames="tx_blogexample_domain_model_post" AND fieldname="categories"'
+               );
+               $this->assertSame(4, $countCategories);
+       }
+
+       /**
         * Helper method for persisting blog
         */
        protected function updateAndPersistBlog() {
@@ -442,3 +510,4 @@ class RelationTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
                $this->persistentManager->persistAll();
        }
 }
+