When using includes
on an ActiveRecord model, is there a better way to specify an inner join then:
User.includes(:address).joins(:address)
It seems like there should be a more beautiful way to specify when you want an inner join and an includes?
What is the difference between includes and joins? The most important concept to understand when using includes and joins is they both have their optimal use cases. Includes uses eager loading whereas joins uses lazy loading, both of which are powerful but can easily be abused to reduce or overkill performance.
1 What is Active Record? Active Record is the M in MVC - the model - which is the layer of the system responsible for representing business data and logic. Active Record facilitates the creation and use of business objects whose data requires persistent storage to a database.
ActiveRecord::Base indicates that the ActiveRecord class or module has a static inner class called Base that you're extending. Edit: as Mike points out, in this case ActiveRecord is a module...
ActiveRecord is an ORM. It's a layer of Ruby code that runs between your database and your logic code.
As Tom Rossi explained in the comment section of your question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With