Search for disctint values using the ORM

Bug #557326 reported by Numérigraphe
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Confirmed
Wishlist
OpenERP's Framework R&D
Nominated for Trunk by Numérigraphe

Bug Description

Answers for Question #106692 indicate that for the moment we can't do a "SELECT DISTINCT" using the ORM : see https://answers.launchpad.net/openobject-addons/+question/106692
There are cases where this would be useful (like searching the order ids in order lines), so I propose we add a new parameter "distinct=False" to the read() method of th OSVs.
When set to True, it would return distinct tuples only.
It seems easy to add in osv using a SELECT DISTINCT statement.
It may be a bit more tricky in osv_memory, and it will run slower of course, and none sane will use it there I suppose, so we should just throw a "not implemented" exception I guess.
Lionel

Changed in openobject-server:
importance: Undecided → Wishlist
Revision history for this message
xrg (xrg) wrote : Re: [Bug 557326] [NEW] Search for disctint values using the ORM

On Wednesday 07 April 2010, you wrote:
> Public bug reported:
>
> Answers for Question #106692 indicate that for the moment we can't do a
> "SELECT DISTINCT" using the ORM. There are cases where this would be
> useful (like searching the order ids in order lines), so I propose we add
> a new parameter "distinct=False" to the search() method of th OSVs. When
> set to True, it would return distinct tuples only.
> It seems easy to add in osv using a SELECT DISTINCT statement.
> It may be a bit more tricky in osv_memory, and it will run slower of
> course, and none sane will use it there I suppose, so we should just throw
> a "not implemented" exception I guess. Lionel
>

Aren't the orm.search() and orm.read() results already distinct, by definition?
Those functions use the id column as a key, and thus never expected to return
duplicate results.

Or am I missing something?

Revision history for this message
Albert Cervera i Areny - http://www.NaN-tic.com (albert-nan) wrote :

A Dissabte, 10 de juliol de 2010, xrg va escriure:
> On Wednesday 07 April 2010, you wrote:
> > Public bug reported:
> >
> > Answers for Question #106692 indicate that for the moment we can't do a
> >
> > "SELECT DISTINCT" using the ORM. There are cases where this would be
> > useful (like searching the order ids in order lines), so I propose we
> > add a new parameter "distinct=False" to the search() method of th OSVs.
> > When set to True, it would return distinct tuples only.
> >
> > It seems easy to add in osv using a SELECT DISTINCT statement.
> > It may be a bit more tricky in osv_memory, and it will run slower of
> >
> > course, and none sane will use it there I suppose, so we should just
> > throw a "not implemented" exception I guess. Lionel
>
> Aren't the orm.search() and orm.read() results already distinct, by
> definition? Those functions use the id column as a key, and thus never
> expected to return duplicate results.
>
> Or am I missing something?

Well, the thing is that search() function doesn't receive a list of fields so
it's not possible to execute a SELECT DISTINCT in search function. IMHO read()
function should accept both a list of IDS and a domain. In the latter case
it'd be possible what the bug report asks for.

--
Albert Cervera i Areny
http://www.NaN-tic.com
OpenERP Partners
Mòbil: +34 669 40 40 18

http://twitter.com/albertnan
http://albert-nan.blogspot.com

description: updated
description: updated
Revision history for this message
Numérigraphe (numerigraphe) wrote :

xrg & Albert Cervera i Areny : search() returns ids so yes it's probably already distinct. The feature is missing in read(), not search() - I must have been distracted.

xrg: it's quite common for search to return several identical tuples when different ids are passed. One example is: search for the order id in sale order lines.

Maybe distinct should be the default but that requires a lot of testing, I wouldn't recommend it for v6.0.

Albert Cervera i Areny
> IMHO read() function should accept both a list of IDS and a domain.
Yes I think Tryton made it this way too, please file a distinct bug report.

Lionel.

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Adding a way to select distinct values seems like an interesting improvement post-v6, along with search_read and the likes..

Thanks for the suggestion

Changed in openobject-server:
assignee: nobody → OpenERP's Framework R&D (openerp-dev-framework)
status: New → Confirmed
Revision history for this message
Numérigraphe (numerigraphe) wrote :

Has this been implemented already?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.