Add a "distinct" argument to selectData() method (defaults to false)

Description

So that programmers can avoid duplicate records in their result sets.

Activity

Show:
Jan Jannek
March 29, 2016, 3:20 PM

It would be good to have this option in the selectManyToManyData method as well.
I had the following use case:

A blog_post hast a many-to-many relationship to tags
Now I want to filter (e.g. for a view or widget) and get posts for a defined set of tags, meaning the blog post matches if it has at least one of the specified tags.
I ended up doing the following:
1. selectManyToManyData to just return the blog post IDs (this resulted in possible multiple records
2. build array/list of IDs from the query result
3. use this blog ID list with selectData to get the actual data

It would be easily solved with a distinct option, that way i would be able to get the actual blog data from the selectmanytomanydata function. it might also work with select data directly. but for sure it would only require one SQL statement either way.

As I learned it is possible to "hack" the system by supplying "distinct" in the selectFields list, e.g. selectFields = [ "distinct blog_post.id", "blog_post.title", ... ]
The solution is not obvious and it would be nice if "distinct" would work out of the box as a boolean argument (default to "false")

Manikandan M
October 6, 2016, 6:10 AM

Assignee

Dominic Watson

Reporter

Dominic Watson

Labels

None

Accepted

Yes

Fix versions

Priority

Medium
Configure