加入多个表来获取电子邮件ID

时间:2015-02-25 06:54:02

标签: ruby-on-rails ruby ruby-on-rails-3 postgresql activerecord

我有3个模特

aff.rb

has_many :tic_affs, inverse_of: :aff, dependent: :restrict_with_exception
has_many :tic, through: :tic_affs

tic.rb

has_one  :tic_aff, inverse_of: :tic, dependent: :restrict_with_exception
has_one  :aff, through: :tic_aff

use.rb

has_one :aff, inverse_of: :use, dependent: :restrict_with_exception
has_many :tics, class_name: "Tic"

我想使用连接从用户表中获取电子邮件ID,任何人都可以帮我构建Rails查询

这是我写的用于获取电子邮件ID的查询

select uses.email 
from tic_affs 
FULL OUTER JOIN affs ON tic_affs.aff_id=affs.id 
JOIN uses ON affs.use_id=uses.id;

如果此查询是正确的,请帮我将其构建为rails查询

0 个答案:

没有答案