Joins
Performing Inner Table Joins
NoBrainer allows inner table joins on associations with join()
.
Suppose we have posts and comments:
join()
accepts arrays and hashes to describe the associations to join,
similarly to eager_load()
.
Examples
The first example shows a table join on a belongs_to
association between posts
and authors:
join()
performs an inner join on the provided associations, the query
iterates on posts that have an author.
The second example shows two joins on has_many
associations.
The query provides one entry per author, per post and per comment, generating
lots of objects. To avoid this, use eager_load()
described in the next
section.