5

Hello I'm using phalcon Framework.

I need to make a find, normally I would use distinct, but I not found an option.

My class as below :

class Calls extends \Phalcon\Mvc\Collection {
public $agent;
public $number;
public $date;
public $status;
}

I need to use distinct fields date and number ?

Neo-coder
  • 7,715
  • 4
  • 33
  • 52
  • Try to use native php. $retval = $col->distinct("field_name"); http://php.net/manual/en/mongocollection.distinct.php – learner Nov 09 '15 at 05:38
  • I think [this answer](http://stackoverflow.com/questions/30819894/phalcon-how-to-get-distinct-models) will answer your question – Timothy Dec 27 '15 at 23:13

1 Answers1

1

you should use query builder:

Basic implementation for later example:

$queryBuilder = $this->getDI()->getModelsManager()
    ->createBuilder()
    ->addFrom('tableName', 't');

Distinct command:

$queryBuilder->distinct('t.id');

Column thing works too, but not recommended:

$queryBuilder->columns('DISTINCT(t.id) AS id')
Quasipickle
  • 4,383
  • 1
  • 31
  • 53