【发布时间】:2020-02-19 13:05:38
【问题描述】:
我正在那里开发一个 Ruby on Rails 应用程序,
AnalyticsPage 有以下关系。与用户的多对多关系。
class AnalyticsPage < ApplicationRecord
belongs_to :graph_page_layout
has_many :analytics_pages_users
has_many :users, through: :analytics_pages_users
has_many :graph_sections
end
##### query #####
I need to write query where I need to fetch the columns from both of the tables.
analytics_pages = AnalyticsPage.select('users.first_name, users.last_name, analytics_pages.title').joins([:users])
上面的查询没有给出用户的名字和姓氏。另一点是,当我运行 SQL 查询时,它是在 mysql admin 中运行的。
【问题讨论】:
标签: ruby-on-rails join activerecord