Giacomo P. Tue Sep 14 15:52:09 -0400 2010

Subject: Add "DISTINCT" to finder

Hi all,

I'm using PHP 5.3 + mySQL 5.1.31 and I'm looking for how to add a "DISTINCT" to a finder, I would get this query:
SELECT DISTINCT * FROM Options JOIN ...
And I'm using this syntax:

$join = 'JOIN Options_per_Orders ON
(Options.`idoption` = Options_per_Orders.`idoption`) JOIN Orders ON
(Options_per_Orders.`idorder` ='.$order[$i]->idorder.' ) ORDER BY category ASC';

$option = Option::all(array('joins' => $join));

Thank you


Giacomo P. Tue Sep 14 15:59:20 -0400 2010

I found a trick using "GROUP BY" instead of "ORDER BY" but maybe someone need an answer to the question too :)

Jacques Fuentes Tue Sep 14 19:33:35 -0400 2010

You can do the following

$option = Option::all(array('select' => 'DISTINCT *', 'joins' => $join));

Read about it here

asava samuel Thu Mar 07 18:19:32 -0500 2013

Giacomo

Here is an ORM that works with MySQL
https://www.kellermansoftware.com/p-47-net-data-access-layer.aspx

Richard Hendershot Wed Jun 19 09:38:56 -0400 2013

I think OP wanted a finder that could be added to the model subclass. I do. Thinking it's relevant....

I have to use an externally defined schema where a descriptive attribute is non-normalized. Call it Book.Category. Category is a string but no other constraint. I can use your example, but what I really need is to be able to define Book extends Model

find_distinct_categories()

such that I don't have to replicate that SQL throughout my code. I've looked at dynamic finders but they don't appear to support select criteria like distinct. TIA!

(1-4/4)