如何在来自不同数据库的Rails中联接两个表

时间:2019-02-22 10:26:10

标签: mysql ruby-on-rails ruby-on-rails-4 activerecord

我有两个带有用户表的数据库,foreign_key为a_user_id

database_a.users.id, database_a.users.name
database_b.users.id, database_b.users.a_user_id

用户类将与database_a的表相关。

User.joins('INNER JOIN AS b_users ON database_b.users.a_user_id = database_a.users.id')

它引起语法错误:ActiveRecord::StatementInvalid: Mysql2::Error: You have an error in your SQL syntax

0 个答案:

没有答案