Feature #14026
Add new ordering "RAND()" to TYPO3 DB Backend
| Status: | Needs Feedback | Start date: | 2011-03-24 | |
|---|---|---|---|---|
| Priority: | Should have | Due date: | ||
| Assignee: | - | % Done: | 0% |
|
| Category: | Extbase: Generic Persistence | |||
| Target version: | - | |||
| Has patch: | No | Tags: | ||
| Votes: | 4 (View) |
Description
Currently the only allowed sort modes are ascending (ASC) and descending (DESC), but there is no way to order by RAND, which will return a random result set. The only possibility to do that is, to create a native SQL statement and lose the abstraction from a concrete storage backend.
See:
Tx_Extbase_Persistence_Storage_Typo3DbBackend::parseOrderings()
History
Updated by Michael McManus almost 2 years ago
- Has patch set to No
Updated by Ingo Pfennigstorf 9 months ago
- Status changed from New to Needs Feedback
- Target version deleted (
Extbase 1.4)
As the JCR specification that we follow here [1] does not have a RAND or other random ordering and ORDER BY RAND is very MySQL specific (see [2]) I would suggest to reject this feature. What do you think?
[1] http://www.day.com/specs/jcr/1.0/6.6.3.5_Ordering_Specifier.html
[2] http://www.petefreitag.com/item/466.cfm
Updated by Stefan Neufeind 9 months ago
I agree we need some solution that can be used across various DBMS. Thanks for the links.
But we should have random-sorting in some way. So I agree with you that simply using RAND and forgetting about other DBMS is not a solution. But I disagree with you in regards to rejecting this feature-request itself.
Updated by Ingo Pfennigstorf 9 months ago
This is how Doctrine (FLOW3) solved it (not).
http://www.doctrine-project.org/jira/browse/DDC-950
And this is an easy way to implement it in a custom query (german)
http://typo3blogger.de/random-record-repository/
Updated by Stefan Neufeind 9 months ago
Yey, so that's what an ORM is for: Telling you it doesn't care about the database-specific stuff and only leaves creating a custom (DB-dependent solution) as your only option.
The custom repository works in a way. But if you need more rows it even gets a bit more hacky. (Yes you could do a fetch where uid in (...) and shuffle them inside php). So exactly that "custom solution" that everybody needing a RAND will have to write himself is not really an option imho.
Now if Doctrine doesn't want to help, and if Extbase needs to find a way to do it that FLOW3 will be fine with as well, what's our option? Put database-dependent stuff inside Extbase/FLOW3 since Doctrine doesn't want to care about it? Hmm ...