Giter VIP home page Giter VIP logo

Comments (3)

alxsabo avatar alxsabo commented on July 20, 2024

Those are two different queries, and you can't use them in the way you mentioned.

First query when translated to RQL, it will be:

$session->query(Site::class)
->whereEquals("userId", $userId)
->toList();
from "Sites" 
where userId == "UserID"

and if you create a query with count(), it will create RQL like:

$session->query(Site::class)
->whereEquals("userId", $userId)
->count();
from "Sites"
where userId == "UserID" limit 0, 0

The method count() will return just an integer value. PHP client will send this query to the server to get the number of documents, but it will not return any document from the server. More about count can be found in the documentation: https://ravendb.net/docs/article-page/5.4/csharp/client-api/session/querying/how-to-count-query-results

It would be best to leave out the count() part for the mentioned case because 'toList()' method will always return an array.

from ravendb-php-client.

ayende avatar ayende commented on July 20, 2024

Another thing to consider is that RavenDB doesn't need a separate query.
You can use the getQueryStatistics() to get the results in one remote call.

See:
https://github.com/ravendb/ravendb-php-client/blob/00c504c11fc250f1d0304f2a70bca06d1601014e/tests/Test/Client/Spatial/_SpatialTest/SpatialTest.php#L39C4-L47

$statsRef = new QueryStatistics();
$query = $session->query(Site::class)->whereEquals("userId", $userId);
$results = $query->statistics($statsRef)->toList();
$totalResults = $statsRef->getTotalResults();

from ravendb-php-client.

plexcellmedia avatar plexcellmedia commented on July 20, 2024

Thank you both of you! It just felt like an issue, because the call to $query->count() overrides the $query variable, which it before didn't do. But this resolves with using statistics or changing our approach a little bit.

from ravendb-php-client.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.