danielmewes / php-rql

A PHP client driver for the RethinkDB query language (ReQL).
http://php-rql.dnsalias.net/
339 stars 60 forks source link

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

Open martemorfosis opened 8 years ago

martemorfosis commented 8 years ago

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.

Geekimo commented 8 years ago

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