How to select record by position

1

Can you tell me how I can select a record by position?

How would you search for Maria's record? obs: do not search by id or name

I found the take in the guide, but it looks for the first and the position. ex:

Person.take(3) // ele pegaria fabio e maria

Bank:

Fabio

Roberto

Maria

Joao

Diego

    
asked by anonymous 02.12.2016 / 13:33

2 answers

2

take actually gets the first 3 records (uses LIMIT for this) Ex:

Person.take(3)

would generate an sql: SELECT "usuarios".* FROM "usuarios" LIMIT 3

For a few records something like the solution below would solve:

Person.take(3)[2] # terceiro registro

But for a more performative solution I would not recommend this solution, since to query from a very distant position, this method would bring with it an enormous amount of data.

For example, getting the 1,000,000 item would fetch these millions of records.

If you have other factors to limit this data, this solution can be used.

    
02.12.2016 / 20:43
1

With the proposed record sample,

Person.third

would return the record 'maria'.

    
03.12.2016 / 12:14