danielmewes / php-rql

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

Closures are not working inside operations #156

Closed jarnojellesma closed 5 years ago

jarnojellesma commented 7 years ago

Closures inside the Rql methods e.g. filter, insert, update are not working.

Example (also doesn't work when using an actual example) e.g: https://stackoverflow.com/questions/36248729/rethinkdb-and-php-rql-how-to-filter-match-at-the-same-time https://github.com/rethinkdb/rethinkdb/issues/1877 https://stackoverflow.com/questions/40820750/rethinkdb-php-rql-append-to-nested-field

$cursor = r\db($this->getDb())->table($this->getTable())
                ->get($this->id)

                ->update(function($doc) { return; })

                ->run($connection);

In the Update class the $delta = $this->nativeToDatum($delta) method gets called.

if (!(is_object($delta) && is_subclass_of($delta, "\\r\\Query"))) {
            try {
                $json = $this->tryEncodeAsJson($delta);
                if ($json !== false) {
                    $delta = new Json($json);
                } else {
                    $delta = $this->nativeToDatum($delta);
                }
            } catch (RqlDriverError $e) {
                $delta = $this->nativeToFunction($delta);
            }
        }

This method is in the DatumConverter class. This method returns null. Which creates this exception:

TypeError: Argument 1 passed to r\DatumConverter::wrapImplicitVar() must be an instance of r\Query, null given