# Geavanceerde ActiveRecord-query's (Ruby on Rails) > Query interface, where, joins, includes, eager loading, N+1-probleem, transactions, locking (optimistic/pessimistic) - 28 gespreksvragen - Mid-Level - [Gespreksvragen: Ruby on Rails](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen.md) ## 1. Welke ActiveRecord-methode haalt een record op aan de hand van de primaire sleutel en gooit een exception als het niet wordt gevonden? **Antwoord** De find-methode haalt een record op aan de hand van de primaire sleutel en gooit een ActiveRecord::RecordNotFound-exception als het record niet bestaat. Dit zorgt ervoor dat de code expliciet faalt in plaats van door te gaan met een nil-waarde. Om de exception te vermijden en in plaats daarvan nil terug te geven, gebruik je find_by(id: value). ## 2. Wat is het belangrijkste verschil tussen find_by en where.first in ActiveRecord? **Antwoord** find_by geeft direct een enkel record of nil terug, terwijl where.first een ActiveRecord-relatie teruggeeft en vervolgens first aanroept om het eerste resultaat te krijgen. In de praktijk genereert find_by een geoptimaliseerde query met LIMIT 1, terwijl where mogelijk meer gegevens laadt voordat het eerste element wordt geselecteerd. ## 3. Hoe geef je meerdere voorwaarden door aan de where-methode in ActiveRecord? **Antwoord** De where-methode accepteert een hash met meerdere sleutels om meerdere voorwaarden op te geven die met AND worden gecombineerd. Bijvoorbeeld, User.where(status: 'active', role: 'admin') genereert WHERE status = 'active' AND role = 'admin'. Voor OR-voorwaarden gebruik je or of ruwe SQL-query's. ## Nog 25 vragen beschikbaar - Wat is het N+1-probleem in ActiveRecord? - Welke methode gebruik je om het N+1-probleem op te lossen door associaties vooraf te laden? Meld je gratis aan: https://sharpskill.dev/nl/login ## Andere Ruby on Rails-sollicitatieonderwerpen - [Ruby-basis](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/ruby-basics.md): 25 vragen, Junior - [Objectgeoriënteerd programmeren in Ruby](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/ruby-oop.md): 20 vragen, Junior - [Rails-grondbeginselen](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/rails-fundamentals.md): 18 vragen, Junior - [Routing & Controllers](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/routing-controllers.md): 22 vragen, Junior - [ActiveRecord-basis](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/active-record-basics.md): 25 vragen, Junior - [Views & ERB-templates](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/views-erb-templates.md): 20 vragen, Junior - [ActiveRecord-associaties](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/active-record-associations.md): 24 vragen, Mid-Level - [Rails-formulieren](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/rails-forms.md): 20 vragen, Mid-Level - [Authenticatie & autorisatie](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/authentication-authorization.md): 22 vragen, Mid-Level - [Moderne Asset Pipeline & frontend](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/rails-asset-pipeline.md): 18 vragen, Mid-Level - [Rails API-modus](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/rails-api-mode.md): 20 vragen, Mid-Level - [Testen met RSpec](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/rails-testing-rspec.md): 24 vragen, Mid-Level - [ActiveJob & Background Jobs](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/active-job-background-jobs.md): 20 vragen, Mid-Level - [ActionCable & WebSockets](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/action-cable-websockets.md): 18 vragen, Mid-Level - [ActionMailer](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/action-mailer.md): 18 vragen, Mid-Level - [ActiveStorage](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/active-storage.md): 20 vragen, Mid-Level - [Cachingstrategieën](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/caching-strategies.md): 20 vragen, Mid-Level - [Geavanceerde migraties](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/database-migrations-advanced.md): 20 vragen, Mid-Level - [Rails Engines & modulaire apps](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/rails-engines-modular-apps.md): 18 vragen, Senior - [Prestatie-optimalisatie](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/performance-optimization.md): 26 vragen, Senior - [Rails Design Patterns](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/rails-design-patterns.md): 22 vragen, Senior - [Ruby-metaprogrammering](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/ruby-metaprogramming.md): 20 vragen, Senior - [Rails-beveiliging](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/rails-security.md): 22 vragen, Senior - [GraphQL met Rails](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/graphql-rails.md): 20 vragen, Senior - [Deployment & Productie](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/rails-deployment-production.md): 20 vragen, Senior - [Monitoring & Logging](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/monitoring-logging.md): 20 vragen, Senior - [Rails-upgradestrategieën](https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/rails-upgrade-strategies.md): 18 vragen, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/nl/technologies/ruby-on-rails/sollicitatievragen/active-record-queries