php-rql icon indicating copy to clipboard operation
php-rql copied to clipboard

'Branch' accepts only 2 + 1 arguments, not 2n +1 as expected.

Open martemorfosis opened this issue 9 years ago • 1 comments

I was trying to run this query which works perfectly on RethinkDB's Query Browser and JS Driver:

r.branch(
    r.expr(x).match('^avg'),
    r.expr(r.table('test')('statistics')(x).avg()),
    r.expr(x).match('lg'),
    r.expr(r.table('test')('statistics')(x).max()),
    r.expr(r.table('test')('statistics')(x).sum())
)

But in PHP when the first test was false I was getting the result of 'match'. The only workaround I found was to nest another 'branch' sentence in my PHP query:

r\branch(
r\expr($x)->match('^avg'),
r\expr(r\table('test')->getField('statistics')->getField($x)->avg()),
r\branch(
    r\expr($x)->match('lg'),
    r\expr(r\table('test')->getField('statistics')->getField($x)->max()),
    r\expr(r\table('test')->getField('statistics')->getField($x)->sum())
   )
)

In RethinkDB's docs and on PHP-RQL ones it is stated that 'Branch' works with 2n +1 arguments which is not the case on the current PHP implementation.

martemorfosis avatar Sep 21 '16 21:09 martemorfosis

I will take a look at it asap. I had the same issue with other methods.

Geekimo avatar Sep 30 '16 21:09 Geekimo