Model resultset find and specific operations

Hi, As per docs

the find() method returns a Phalcon\Mvc\Model\Resultset\Simple. This is an object that encapsulates all the functionality a resultset has like traversing, seeking specific records, counting, etc.

Say I have a "units" table with type as big , small, large.

I can do

      $result = Units::find():
      $totalRecords = $result->count();

However, is it possible to find total on the basis of type ie. how many large , small and big units are in there from resultset itself and without making another query to DB ?

Hi @iRickyj is it the same problem as before?


Not really, actually real problem is that I have worked a lot with procedural programming but never with any framework and OOP, so here my doubt is more about resultset object created using find().

When we do this on resultset : $totalRecords = $result->count();

Are we using new sql like SELECT count("type") FROM "units"; or its couting number of records from Object itself ?

Similarly, once we have a resultset , can we do things similar to : SELECT count("type") FROM units WHERE type = 'large'; but without actually connecting to DB as we already have all data from MODEL::find() ?


unless so

$UserSession = UserSession::query() ->columns([ "COUNT() AS count_total", "(SELECT COUNT() FROM UserSession WHERE compromised = TRUE) AS count_compromised", "(SELECT COUNT(*) FROM UserSession WHERE active = TRUE) AS count_active", ]) ->cache([ "key" => "sessions_info" ]) ->execute() ->getFirst() ->toArray();

to go through everything in memory is resource intensive


Thanks but I am still naive in all this, can you explain what you are try to say ?