Sails: Select random records

Created on 4 Jul 2014  路  9Comments  路  Source: balderdashy/sails

How would I .sort(random)?

SQL queries allow ORDER BY RAND() or ORDER BY RANDOM(), which is very useful when querying for 10 records at random.

Is this possible? Or would I have to retrieve them all and the randomly select from the returned array?

Most helpful comment

Any update?
It feels like waterline deprecates itself..

All 9 comments

Waterline doesn't currently support this. If you are using a sql database you can use .query() and write a sql query that will return random values.

This would be a very cool addition... Hope this gets added soon...

I too would like to voice my support for this. Do we need to open a new feature request for this?

:+1: why is this ticket closed? This is a very important feature.

Hi @secrettriangle, I believe this was closed because this can be done with .query(). Do you know if other data stores (outside SQL ones) support sorting randomly?

@dmarcelino I don't know about other databases but I know PostgreSQL supports this, which is my use case.

The reason I ask is because if this is a PostgreSQL specific feature then it should be implemented in the sails-postgresql adapter. If such implementation requires waterline core changes then it's worth re-opening this.

I don't think it would be PostgreSQL specific, but might have to be implemented within Waterline itself if a database backend doesn't support it.

Any update?
It feels like waterline deprecates itself..

Was this page helpful?
0 / 5 - 0 ratings

Related issues

3imed-jaberi picture 3imed-jaberi  路  3Comments

thomasfr picture thomasfr  路  3Comments

mahfuzur picture mahfuzur  路  3Comments

pawankorotane picture pawankorotane  路  3Comments

Alirezamohammadi picture Alirezamohammadi  路  4Comments