W
W
WEB_champion2014-11-10 14:36:08
Ruby on Rails
WEB_champion, 2014-11-10 14:36:08

How can I find out in RoR in which line a certain record is located in the database?

Let's say there is a User table with the following content in the database:
id | login
4 | my_login34
7 | my_login4
3 | my_login11
How can I make a selection from the table and find out in which line this entry is located, for example, my_login4 is in the second line, but how can I find out by making a selection from the table:
u = User.where(login: 'my_login4').first ?? ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Vsk, 2014-11-10
@WEB_champion

Or add a field that will contain the position of each and recalculate each time the table changes.
Or User.pluck(:login).index("my_login4")remember to index the login field
. But in general, the idea is doubtful. Why is this needed?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question