Testing ActiveRecord associations in the Rails console

21-Jan-2019 2104
When building a new Rails app, you usually get to create several models with all kinds of associations between them (see more in the documentation).The usual steps after creating the app would be as follows:Create the ActiveRecord models.Build the ActiveRecord associations within the models (e.g. belongs_to, has_many, has_many: through etc.)Create the db tables and migrations.Check the schema to verify that the tables have the correct structure.Test the ActiveRecord models associations.This last step is the one we will cover in this tutorial. It is a fairly simple task once you understand the basics, and it can save you a lot of trouble later on when building up on the functionality of your app.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle