June 9, 2020 Progate Lv.85 I used Rails for my lesson assignments
Use ʻorder` to sort the data in ascending order (asc: small order) and descending order (desc: large order).
books = Book.order("id": "asc") #Arrange ids in ascending order books = Book.order("id": "desc") #Arrange ids in descending order
limit to specify the upper limit of the value to be retrieved.
books = Book.limit(100).order("id": "desc") #Get up to 100 values
As in the example, ʻorder
can be described in one line by using limit
and dot (.`).
Use ʻall` to get all values as opposed to limit.
books = Book.all
where to get the values that match the conditions in the table.
books.where("author=Ryunosuke Akutagawa") #authorカラムがRyunosuke Akutagawaのレコードを全て取得。