I have two tables: fe_users (for my frontend users) and tx_somethingarticles_domain_model_article. A user should be able to "like" an article, so for every user I need the information if he already liked an article or not, but also do I need the information how many likes an article already has. So I believe what I need is a bidirectional mm relation, but I just cant seem to make it work. I have my User Entity, which looks like this:
/**
* articleLike
*
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Package\SomethingArticles\Domain\Model\Article>
*/
protected $articleLike = NULL;
public function addArticlesLike(\Package\SomethingArticles\Domain\Model\Article $articlesLike) {
$this->articlesLike->attach($articlesLike);
}
public function removeArticlesLike(\Package\SomethingArticles\Domain\Model\Article $remove) {
$this->articlesLike->detach($remove);
}
public function getArticlesLike() {
return $this->articlesLike;
}
public function setArticlesLike(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $articlesLike) {
$this->articlesLike = $articlesLike;
}
My Article Entity has this: protected $articlesLike = NULL;
public function getArticlesLike() {
return $this->articlesLike;
}
with getArticlesLike I want to get all likes for an article. My tca.php for User has the column articles_like and looks like this:
'articles_like' => array(
'exclude' => 1,
'label' => 'LLL:EXT:something_articles/Resources/Private/Language/locallang_db.xlf:tx_somethingarticles_domain_model_user.articles_like',
'config' => array(
'type' => 'group',
'internal_type' => 'db',
'foreign_table' => 'tx_somethingarticles_domain_model_article',
'allowed' => '*',
'MM' => 'tx_somethingarticles_user_articleslike_article_mm',
'MM_opposite_field' => 'articles_like',
'size' => 10,
'autoSizeMax' => 30,
'maxitems' => 9999,
'multiple' => 0,
),
),
and the tca.php for my articles:
'articles_like' => array(
'exclude' => 1,
'label' => 'LLL:EXT:something_articles/Resources/Private/Language/locallang_db.xlf:tx_somethingarticles_domain_model_article.articles_like',
'config' => array(
'type' => 'group',
'internal_type' => 'db',
'allowed' => '*',
'foreign_table' => 'fe_users',
'MM' => 'tx_somethingarticles_user_articleslike_article_mm',
'maxitems' => 9999,
),
),
When I fetch a user and try something like $user->getArticlesLike() it works perfectly, I can also attach new likes, works like a charm. But when I try $article->getArticlesLike() ... its always empty. What am I missing?
I'm really desperate here, I've been trying to solve this for the last 10 hours, I can't seem to find a solution. Any help is appreciated greatly.
'foreign_table' => 'fe_users'- Chi