mardi 24 février 2015

Joining Multiple table to fetch email id

I have 3 models


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"


i want to fetch email id from user table using joins could any one please help me in framing the Rails query


This is the query i wrote to fetch email id's



select users.email
from ticket_affiliates
FULL OUTER JOIN affiliates ON ticket_affiliates.affiliate_id=affiliates.id
JOIN users ON affiliates.user_id=users.id;


if this query is right help me framing this into rails query


Aucun commentaire:

Enregistrer un commentaire