# ActiveRecord Associations (Ruby on Rails) > has_many, belongs_to, has_one, has_and_belongs_to_many, polymorphic, dependent destroy - 24 interview questions - Mid-Level - [Interview Questions: Ruby on Rails](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions.md) ## 1. Which association should be used in a Comment model to indicate that a comment must belong to an article? **Answer** The belongs_to association is used to define a relationship where a record belongs to another. In this case, a Comment belongs to an Article. By convention, this implies that the comments table contains an article_id column which is a foreign key to the articles table. ## 2. Which association should be used in an Article model to allow having multiple associated comments? **Answer** The has_many association defines a one-to-many relationship. An Article can have multiple Comments. This association is the mirror of belongs_to and does not store a foreign key in its own table, but expects the associated model (Comment) to have an article_id column. ## 3. Which association should be used for a user to have a single profile, where the profile contains the foreign key? **Answer** The has_one association defines a one-to-one relationship where the other model contains the foreign key. In the case User has_one :profile, the profiles table will contain a user_id column. This is the inverse of has_one/belongs_to depending on where the foreign key is located. ## 21 more questions available - How to model a many-to-many relationship between Post and Tag with a join table containing additional attributes? - What is the default behavior of the dependent: :destroy option on a has_many association? Sign up for free: https://sharpskill.dev/en/login ## Other Ruby on Rails interview topics - [Ruby Basics](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/ruby-basics.md): 25 questions, Junior - [Ruby Object-Oriented Programming](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/ruby-oop.md): 20 questions, Junior - [Rails Fundamentals](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/rails-fundamentals.md): 18 questions, Junior - [Routing & Controllers](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/routing-controllers.md): 22 questions, Junior - [ActiveRecord Basics](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/active-record-basics.md): 25 questions, Junior - [Views & ERB Templates](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/views-erb-templates.md): 20 questions, Junior - [Advanced ActiveRecord Queries](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/active-record-queries.md): 28 questions, Mid-Level - [Rails Forms](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/rails-forms.md): 20 questions, Mid-Level - [Authentication & Authorization](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/authentication-authorization.md): 22 questions, Mid-Level - [Modern Asset Pipeline & Frontend](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/rails-asset-pipeline.md): 18 questions, Mid-Level - [Rails API Mode](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/rails-api-mode.md): 20 questions, Mid-Level - [Testing with RSpec](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/rails-testing-rspec.md): 24 questions, Mid-Level - [ActiveJob & Background Jobs](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/active-job-background-jobs.md): 20 questions, Mid-Level - [ActionCable & WebSockets](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/action-cable-websockets.md): 18 questions, Mid-Level - [ActionMailer](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/action-mailer.md): 18 questions, Mid-Level - [ActiveStorage](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/active-storage.md): 20 questions, Mid-Level - [Caching Strategies](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/caching-strategies.md): 20 questions, Mid-Level - [Advanced Migrations](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/database-migrations-advanced.md): 20 questions, Mid-Level - [Rails Engines & Modular Apps](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/rails-engines-modular-apps.md): 18 questions, Senior - [Performance Optimization](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/performance-optimization.md): 26 questions, Senior - [Rails Design Patterns](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/rails-design-patterns.md): 22 questions, Senior - [Ruby Metaprogramming](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/ruby-metaprogramming.md): 20 questions, Senior - [Rails Security](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/rails-security.md): 22 questions, Senior - [GraphQL with Rails](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/graphql-rails.md): 20 questions, Senior - [Deployment & Production](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/rails-deployment-production.md): 20 questions, Senior - [Monitoring & Logging](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/monitoring-logging.md): 20 questions, Senior - [Rails Upgrade Strategies](https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/rails-upgrade-strategies.md): 18 questions, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/en/technologies/ruby-on-rails/interview-questions/active-record-associations