Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/scope_delegation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ def delegate_scope(name, options)
source = options[:scope] || name
association = reflect_on_association(options[:to]) || raise("Unknown association")
name = [options[:prefix], name].compact.join("_")
grouping = options[:group]

scope name, Proc.new { |*args|
joins(association.name).merge(association.klass.send(source, *args))
if grouping
joins(association.name).merge(association.klass.send(source, *args)).group(grouping)
else
joins(association.name).merge(association.klass.send(source, *args))
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could do something like

relation = joins(association.name).merge(association.klass.send(source, *args))
relation = relation.group(grouping) if grouping
relation

to reduce the bit of duplication

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tried it and it broke things...i can dive in a little more next FF...and add specs :)

}
end
end