I have 3 tables: articles
, people
and person_mentions
.
Article
model has_many :people, through: person_mentions
and so on.
In person_mentions
table I have 3 columns article_id
, person_id
and mention_order
. mention_order
is an integer.
I need to find all people, who mentioned in article and order them by mention_order
, but when I run
@article.people.order(mention_order: :asc)
I get an error
column people.mention_order does not exist
So, I need to make a query from people
table with mention_order
from person_mentions
in it.
Thanks for any help!
你能尝试一下:
@article.people.order("person_mentions.mention_order asc")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.