[TYPO3-mvc] Query constraints using MM relations
Jacob Rasmussen
jacob at lightbulb.dk
Tue Mar 22 19:39:32 CET 2011
Hi list,
I'm trying to port an application to Extbase and I've stumbled upon an
annoyance, as I try to filter a query/repository using data from MM
relations.
The problem is that when I supply the method $query->in(property,
operand) with a list of foreign UIDs as operand, I expect the query to
perform a lookup in the MM or foreign table... instead the comparison is
done directly on the property value.
To demonstrate:
My object contains a field with the following TCA configuration:
...
'sogne' => array(
'label' => ...
'config' => array(
'type' => 'select',
'foreign_table' => 'tx_churchbase_sogn',
'foreign_table_where' => 'ORDER BY tx_churchbase_sogn.sogn'
'size' => 6,
'maxitems' => 100,
'MM' => 'tx_churchbase_sogn_mm',
'MM_match_fields' => array(
'ident' => 'tx_churchbase_bygninger'
),
)
),
...
The MM table is linking from the table to a lot of different tables,
which is why I use MM_match_fields and since I don't have a field in the
tx_churchbase_sogn table, which shows all related elements in other
tables, I choose not to use the tablenames field
The Domain Model looks like this:
class Tx_Churchbase_Domain_Model_Bygning extends
Tx_Extbase_DomainObject_AbstractEntity {
/**
* @var
Tx_Extbase_Persistence_ObjectStorage<Tx_Churchbase_Domain_Model_Sogn>
*/
protected $sogne;
public function __construct() {
$this->sogne = new Tx_Extbase_Persistence_ObjectStorage();
}
...
And there is of course getters and setters just like BlogExample
}
If I do a query on the associated repository and outputs sogne, they are
filled with objects from the tx_churchbase_sogn table, so the objects
link like they should.
But I would like to make a custom filter in the Domain Repository for
Tx_Churchbase_Bygning, so I added a method in the repository class:
public function findBySogne() {
return $query->matching(
$query->in('sogne', array(1, 2))
)->execute();
}
So I naturally expect that the query will get any objects of the
Tx_Churchbase_Bygning type, which has a relation to uid 1 and 2 in the
tx_churchbase_sogn table (or objects with the aforementioned UIDs if you
like).
But instead the query will return any Tx_Churchbase_Bygning object which
has 1 or 2 relations to the tx_churchbase_sogn table...
Am I using the framework wrong - or should I make bug report?
Btw. sorry for the long post, it's just a bit tricky to explain the
issue :-)
--
Kind regards
Jacob Rasmussen
Certified TYPO3 Integrator
More information about the TYPO3-project-typo3v4mvc
mailing list