Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Add parenthesis to NestedSet behavior tree filter methods #740

Open
ienzam opened this Issue Aug 17, 2013 · 0 comments

Comments

Projects
None yet
1 participant

ienzam commented Aug 17, 2013

Hi,
Current implementation of tree filter methods like

query descendantsOf($node)
query branchOf($node)
query childrenOf($node)
query siblingsOf($node)
query ancestorsOf($node)
query rootsOf($node)

are adding two or more condition to the query class, but is not grouped into a parenthesis.

So we cannot do a query like

$query->rootsOf($node1)->_or()->rootsOf($node2);

Adding parenthesis to the queries will make it easier to do such queries.

Use case:

An article has more than one categories. And we need to search for related articles which have one of the categories or their descendents as their category.

Example:

There are categories - cat1, cat1.1, cat2, cat2.1, cat2.2, cat2.3, cat3, cat3.1, cat3.2

Article 1 has categoris - cat1.1, cat2, cat3.1

Article 2 has category - cat1

Article 3 has category - cat2.2, cat1

Article 4 has category - cat3.2, cat2

So Article 1 has Article 3 (because it has cat2.2) and Article 4 (because it has cat2) as its related article.

If the tree filter methods are parenthesized, we can do this in one query

ArticleQuery()::create()
->useCrossQuery()->useCategoryQuery()
->branchOf(cat1.1)
->_or()
->branchOf(cat2)
->_or()
->branchOf(cat3.1)
->endUse()->endUse()
->find();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment