Skip to content

Commit

Permalink
translated attributes as part of the join where
Browse files Browse the repository at this point in the history
  • Loading branch information
kiliancs committed Jun 26, 2015
1 parent a0e056b commit beeec24
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib/globalize/active_record/class_methods.rb
Expand Up @@ -7,6 +7,10 @@ def with_locales(*locales)
all.merge translation_class.with_locales(*locales)
end

def with_where(opts = {})
all.merge translation_class.where(opts)
end

def with_translations(*locales)
locales = translated_locales if locales.empty?
preload(:translations).joins(:translations).readonly(false).with_locales(locales)
Expand Down
10 changes: 6 additions & 4 deletions lib/globalize/active_record/query_methods.rb
Expand Up @@ -16,7 +16,8 @@ def where(opts = :chain, *rest)
if opts == :chain
WhereChain.new(spawn)
elsif parsed = parse_translated_conditions(opts)
join_translations(super(parsed, *rest))
#join_translations(super(parsed, *rest))
join_translations(super(parsed, *rest), opts)
else
super
end
Expand Down Expand Up @@ -65,12 +66,13 @@ def where_values_hash(*args)
}])
end

def join_translations(relation = self)
def join_translations(relation = self, opts = {})
if relation.joins_values.include?(:translations)
relation
rel = relation
else
relation.with_translations_in_fallbacks
rel = relation.with_translations_in_fallbacks
end
rel.with_where(opts)
end

private
Expand Down

0 comments on commit beeec24

Please sign in to comment.