ernie/squeel — Issue #80: dynamic joins
Author: fringd
Created: 2011-11-22 00:50:40+00:00
State: open

i freaking love that you can do outer joins based on an association... i've been killing myself trying to make this happen...

my only hang up so far with this excellent gem is that it is hard to do *dynamic* joins...

that is, you tell me what you want joined, and i'll join it...

for example you pass me [:albums, :tracks, :format] and i give you Artist.joins{ albums.outer.tracks.outer.format.outer }

or something like that.

right now i'm using this code:

```ruby
join = Squeel::Nodes::Join.new(joins.shift.to_sym).outer
while nextjoin = joins.shift
join = join.send(nextjoin.to_sym).outer
end
scope = scope.joins join
```

which is not really the most user_friendly... it would be nice if

```ruby
to_join = :albums
scope.joins{ `to_join`.outer }
```

worked... actually that doesn't work so hot for the full string...

my intuition was to try something like

scope.joins { send('albums').outer.send('tracks').outer.send('format').outer }

perhaps that could be made to work?