T
T
thorii2016-08-29 16:16:27
Ruby on Rails
thorii, 2016-08-29 16:16:27

How does ActiveRecord even work?

Looked at an example of a command to delete an entry from Ruby

user = User.find_by(name: 'David')
user.destroy

I have not found any normal content describing the general AR interface (what methods and how they are used)
Is it necessary to look for an entry and only then delete it? Or is it easier?
user = User.destroy(name: 'David')

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
forz, 2016-09-08
@foRz

user = User.destroy(name: 'David')
why assign the object to be deleted to a variable?
usually done like this:
User.find_by(name: 'David').destroy
or if you need to delete all records where name: 'David' :
User.where(name: 'David').destroy_all
documentation is full on the basics of AR, including .h. and in Russian

Why, did Roskomnadzor ban the documentation?
devdocs.io/rails~4.2/activerecord/relation#method-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question