Skip to main content
Related: JOINs, References & JOINs — Deep dive, JOINs, Selection, and Grouping, Cascading Use this page when you need to join across collections or model relationships.

Declare associations

app/search_engine/publisher.rb
app/search_engine/book.rb

Query across collections

One-to-one relations

app/search_engine/user.rb
app/search_engine/profile.rb

One-to-many relations

app/search_engine/author.rb
app/search_engine/book.rb

Many-to-many relations

app/search_engine/enrollment.rb
app/search_engine/student.rb
app/search_engine/course.rb
Use belongs_to_many when a single local key maps to many target records via a shared foreign key.

Next steps

  • Learn join rules and nested selection in JOINs.
  • Explore cascading reindex behavior in Cascading.