Active Record - Get the second, third.. item in a database (without ID)

后端 未结 3 1182
终归单人心
终归单人心 2021-01-01 20:45

How to I retrieve the second, third .. entries in a database. I don\'t want to use the auto incrementing id generated by rails.

As I am deleting entries from my data

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-01 21:05

    Say you want the fourth user:

     @users = User.limit(4)
     @fourth_user = @users[3]
    

    Concerning your second question, destroy_all should do the trick since it triggers all callbacks. Be sure to add :dependent => :destroy in your relationships.

提交回复
热议问题