[TYPO3-mvc] tt_news mm-relation
Andrej Maya
A.Maya at esolut.de
Tue Apr 5 15:28:44 CEST 2011
Dear list,
I want to map the tt_news and the tt_news_cat records and to get the
category data together with tt_news content data.
I added the usual typoscript mapping settings like that:
Tx_MyExt_Domain_Model_NewsRelatedInformation{
mapping{
tableName = tt_news
columns{
uid.mapOnProperty = uid
pid.mapOnProperty = pid
title.mapOnProperty = title
keywords.mapOnProperty = keywords
fe_group.mapOnProperty = feGroup
category.mapOnProperty = categories
category.config{
MM = tt_news_cat_mm
foreign_table = tt_news_cat
#MM_table_where =
#foreign_table_where =
#MM_opposite_field = category
#MM_match_fields{}
}
}
}
}
Inside the Tx_MyExt_Domain_Model_NewsRelatedInformation I added the
following necessary properties and methods:
/**
* categories
* @lazy
* @var
Tx_Extbase_Persistence_ObjectStorage<Tx_MyExt_Domain_Model_NewsCategoryR
elatedInformation> $categories
*/
protected $categories;
/**
* The constructor.
*
* @return void
*/
public function __construct() {
//Do not remove the next line: It would break the
functionality
$this->initStorageObjects();
}
/**
* Initializes all Tx_Extbase_Persistence_ObjectStorage instances.
*
* @return void
*/
protected function initStorageObjects() {
/**
* Do not modify this method!
* It will be rewritten on each save in the kickstarter
* You may modify the constructor of this class instead
*/
$this->categories = new
Tx_Extbase_Persistence_ObjectStorage();
}
/**
* Setter for categories
*
* @param
Tx_Extbase_Persistence_ObjectStorage<Tx_MyExt_Domain_Model_NewsCategoryR
elatedInformation> $categories categories
* @return void
*/
public function setCategories(Tx_Extbase_Persistence_ObjectStorage
$categories) {
$this->categories = $categories;
}
/**
* Getter for categories
*
* @return
Tx_Extbase_Persistence_ObjectStorage<Tx_MyExt_Domain_Model_NewsCategoryR
elatedInformation> categories
*/
public function getCategories() {
return $this->categories;
}
/**
* Adds a NewsCategoryRelatedInformation
*
* @param Tx_MyExt_Domain_Model_NewsCategoryRelatedInformation the
NewsCategoryRelatedInformation to be added
* @return void
*/
public function
addCategory(Tx_MyExt_Domain_Model_NewsCategoryRelatedInformation
$category) {
$this->categories->attach($category);
}
/**
* Removes a NewsCategoryRelatedInformation
*
* @param Tx_MyExt_Domain_Model_NewsCategoryRelatedInformation the
NewsCategoryRelatedInformation to be removed
* @return void
*/
public function
removeCategory(Tx_MyExt_Domain_Model_NewsCategoryRelatedInformation
$categoryToRemove) {
$this->categories->detach($categoryToRemove);
}
Extbase builds the sql statement properly (I uncomment the debug($sql)
inside the getObjectDataByQuery function in the Typo3DbBackend.php
class) but if I call this one inside my Controller:
$this->relatedInformation->getCategories()->count(); I get 0 back,
although the sql result have 2 rows.
Is it generally possible the do so with mapping of foreign tables like
tt_news and tt_news_cat??
Kind regards,
Andrej Maya
More information about the TYPO3-project-typo3v4mvc
mailing list