[TYPO3-mvc] Multiple constraints result in query error

Henjo Hoeksma me at henjohoeksma.nl
Thu Oct 13 20:44:26 CEST 2011


Hi list,

I try to parse an array of fields dynamically to a logicalAnd 
statement, but somehow my query gets messed up...
I don't see where it goes wrong, I hope you can help me!

This is a snippet of my repository function:

		foreach($fields as $key => $value) {
		  if(empty($value)) {
			unset($fields[$key]);
		  }
		}
		
		$constraints_array = array();
		foreach ($fields as $key => $value) {
			$constraints_array[] = $query->like($key, '%'.$value.'%');
		}
		$query->matching($query->logicalAnd($constraints_array));

For a single entry in the $fields array this works fine.
When using a second entry in my filter box that adds a second entry in 
the array, somehow the query get's messed up and makes it like:

	tx_extension_domain_model_objet.key1_and_key2

So the keys get combined instead of 2 seperate ones:
	
	tx_extension_domain_model_objet.key1 LIKE ''
	AND
	tx_extension_domain_model_objet.key2 LIKE ''

Does anyone have a clue on why this happens?

Thanks in advance.

Henjo



More information about the TYPO3-project-typo3v4mvc mailing list