[TYPO3-mvc] query for objects with at least one category

Claus Due claus at wildside.dk
Mon Jun 20 20:18:33 CEST 2011


Quick note: the "newsitem.categories.*" should of course be "categories.*" if you do this from the newsitem repository.

/C

On Jun 20, 2011, at 8:16 PM, Claus Due wrote:

> Hi again Dmitri,
> 
> See below :)
> 
> On Jun 20, 2011, at 7:51 PM, Dmitri Pisarev wrote:
> 
>> Hey!
>> Once again I'm stuck...
>> I need to write a query, that shall select all of the objects (with any pid, $query->getQuerySettings()->setRespectStoragePage(FALSE);), that have at least one category assigned (Categories only from storagePid).
>> The only way which I could think out was $query->matching($query->in('category', $categories)); where $categories I have to pass to repository action. Not convinent and didn't work right away.
>> 
>> The other solution would if I could temporary use category field of tt_news as simple int, instead of as a relation, e.g I need this query SELECT * FROM tt_news where category > 0
>> But how do I do it? Set a custom mapping for this field, and map it to a custom property like category_count? Will this work?
>> Any better advice?
>> 
>> Sorry for being silly and annoying!
> 
> Interference from WiFi which makes my Magic TrackPad spazz out is silly and annoying... this is just fun ;)
> 
> Perhaps this could work:
> 
> $constraints = array(
> 	$query->equals('newsitem.categories.pid', $categoryPid),
> 	$query->not($query->equals('newsitem.categories', 0)) // this, because the relation field is actually a count of the number of relations.
> );
> $query->matching($query->logicalAnd($constraints));
> 
> (freestyled again).
> 
> Very unsure if this works as expected...
> 
> Cheers,
> Claus
> 
>> Regards,
>> Dmitri.
>> 
>> 
>> PS:I use the tables from tt_news:
>> config.tx_extbase{
>> 	persistence {
>> 		classes {
>> Tx_Lister_Domain_Model_Article.mapping.tableName = tt_news Tx_Lister_Domain_Model_Category.mapping.tableName = tt_news_cat
>> 		}
>> 	}
>> }
>> _______________________________________________
>> TYPO3-project-typo3v4mvc mailing list
>> TYPO3-project-typo3v4mvc at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
> 
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc



More information about the TYPO3-project-typo3v4mvc mailing list