Skip to content

Commit

Permalink
Handle table aliases in history joins
Browse files Browse the repository at this point in the history
  • Loading branch information
vjt committed Dec 3, 2012
1 parent 5c8fb71 commit 39ab32a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/chrono_model/time_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,12 @@ module QueryMethods
def build_arel
super.tap do |arel|

# Extract joined tables and add temporal WITH if appropriate
arel.join_sources.map {|j| j.to_sql =~ /JOIN "(\w+)" ON/ && $1}.compact.each do |table|
# Extract joined tables and add emporal WITH if appropriate
arel.join_sources.map {|j|
j.to_sql =~ /JOIN "([\w-]+)"(?:\s+"([\w-]+)")? ON/ && [$1, $2]
}.compact.each do |table, alias_|
next unless (model = TimeMachine.chrono_models[table])
with(table, model.history.at(@temporal))
with(alias_ || table, model.history.at(@temporal))
end if @temporal

end
Expand Down

0 comments on commit 39ab32a

Please # to comment.