[TYPO3-mvc] documentation, and example exbase m:n relation query
Helmut Hummel
helmut.hummel at typo3.org
Tue Jul 1 11:55:12 CEST 2014
Hi!
On 30.06.14 09:12, Muriel le Pair wrote:
> Strange... maybe I should rephrase my question, because I just can't
> imagine that it's not possible in extbase.
>
> How you you select all records from the main table where n:m has value 2?
If you have an entity e.g. "News" and it has a property "categories"
which is an m:n relation to "Category" entities, then you could do the
following in your "NewsRepository":
public function findByCategory($category) {
$query = $this->createQuery();
$constraint = $query->contains('categories', $category);
return $query->matching($constraint)->execute();
}
While $category could either be an integer (uid) or an object of type
"Category" entity.
HTH
Kind regards,
Helmut
--
Helmut Hummel
Release Manager TYPO3 6.0
TYPO3 Core Developer, TYPO3 Security Team Member
TYPO3 .... inspiring people to share!
Get involved: typo3.org
More information about the TYPO3-project-typo3v4mvc
mailing list