rails multiple outer joins syntax
Posted
by
Craig McGuff
on Stack Overflow
See other posts from Stack Overflow
or by Craig McGuff
Published on 2012-10-29T10:20:42Z
Indexed on
2012/10/29
11:01 UTC
Read the original article
Hit count: 244
ruby-on-rails-3
|activerecord
I have the following models
user
has_many :leave_balances
leave_balance
belongs_to :user
belongs_to :leave_type
leave_type
has_many :leave_balances
I want to output a table format showing user names and their balance by leave type. Not every user can have every balance i.e. outer joins required.
I'd like to see something like this:
Employee Annual Leave Sick Leave
Bob 10
Fred 9
Sara 12 15
I am unsure how to get this out as a single statement?
I am thinking something like User.joins(:leave_balances).joins(:leave_type)
© Stack Overflow or respective owner