-1

I ran $ rails g model Model and Rails generated two models as follow:

model.rb:

class Event < ApplicationRecord
end

and

application_record.rb:

class ApplicationRecord < ActiveRecord::Base
  self.abstract_class = true 
end

But I was expecting

model.rb:

class Model < ActiveRecord::Base

end

So I came here to find out why. Then I saw this

Why Rails 5 uses ApplicationRecord instead of ActiveRecord::Base?

which means it was because I was using Rails version 5.

I deleted application_record.rb and adjusted model.rb to what am used to:

class Model < ActiveRecord::Base

end

But then am wondering if this has any implication on any other parts of my application that I don't know of know? This is an application I am building and many more features to still add in future.

olucube.com
  • 330
  • 2
  • 11
  • 1
    Welcome to Stack Overflow. Please read "[ask]" and "[mcve]" and their linked pages. Please put in the effort to format your question for readability. Help for formatting is in the edit box as you edit. The effort you put in directly affects our ability to understand your question, and helps us help you. Without that effort many will feel like you didn't try. Remember, SO is an online reference book, and your question is a new article to help others in the future solve the same problem. – the Tin Man May 19 '17 at 06:31

1 Answers1

2

No, there is no actual need for the ApplicationRecord class in the hierarchy. As you already notice it didn't exist in Rails prior version 5.

But it was added to Rails 5 for a good reason because it helps to improve object orientation and the architecture of the app. It helps to share code in the same way the ApplicationController does for controllers.

I would keep it, it might make things easier for you in the future.

spickermann
  • 100,941
  • 9
  • 101
  • 131