yihong0618 和朋友们的频道 头像

消息来源频道

yihong0618 和朋友们的频道

@hyi0618

频道8,612 位成员公开可见0 人在线

yihong0618 和朋友们的频道

成员规模8,612 位成员
在线情况0 人在线
消息总数10,129 条消息
浏览量总数3,271,502 次浏览

在这个频道里搜索消息……

t.me/hyi0618

TIL:
Link: https://github.com/jbranchaud/til/blob/master/rails/disambiguate-where-in-a-joined-relation.md
📌 Disambiguate Where In A Joined Relation
When you join two tables using ActiveRecord
Post.joins(:author)
You get a relation that involves both of the tables. This allows you to
write queries that work off the data in that join.
The primary table in the join is posts. Any column references in a
#where call will be assumed to be related to posts. If you want to
reference a column on the authors table, you'll need to provide that
specificity.
The hash syntax for #where is a great way to do that:
Post.joins(:author).where({ authors: { name: "John Steinbeck" }})
You can also use the string syntax:
Post.joins(:author).where("authors.name = ?", "John Steinbeck")
source