method
joins
v4.0.2 -
Show latest stable
-
1 note -
Class: ActiveRecord::QueryMethods
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0 (0)
- 3.0.9 (0)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (31)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (38)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (-2)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
joins(*args)
public
Performs a joins on args:
User.joins(:posts) => SELECT "users".* FROM "users" INNER JOIN "posts" ON "posts"."user_id" = "users"."id"
You can use strings in order to customize your joins:
User.joins("LEFT JOIN bookmarks ON bookmarks.bookmarkable_type = 'Post' AND bookmarks.user_id = users.id") => SELECT "users".* FROM "users" LEFT JOIN bookmarks ON bookmarks.bookmarkable_type = 'Post' AND bookmarks.user_id = users.id
Register or
log in
to add new notes.
edivandecastro -
January 19, 2012 - (v3.0.0 - v3.1.0)
0 thanks
Options
I came across the following situation An article has a history of friendly url being that the foreign key that represents the value of the article’s id in the table is called Friend url_id then in that case:
Article.joins(“INNER JOIN friends ON articles.id = friends.url_id”).where(“friends.url like ? ”, url)
if the column url_id was renamed for artigo_id would be easier
Article.joins(:friend).where(“friends.url like ? ”, url)