Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Test now passing.

  • Loading branch information...
commit 913a61b7248d83e56921d7a45c48d1924fa40cf6 1 parent 548c82e
@metaskills authored
View
19 TODO
@@ -13,6 +13,21 @@
Notes:
+ >> User.reflections[:boxes]
+ => #<ActiveRecord::Reflection::ThroughReflection:0x007faafdddd538 @macro=:has_many, @name=:boxes, @options={:through=>:columns, :readonly=>false, :order=>"columns.position, boxes.position", :extend=>[UserBoxesAssociationExtension]}, @active_record=User(14 columns), @plural_name="boxes", @collection=true>
+ >> User.reflections[:boxes].source_reflection
+ => #<ActiveRecord::Reflection::AssociationReflection:0x007faafdbf1d00 @macro=:has_many, @name=:boxes, @options={:order=>"position", :extend=>[]}, @active_record=Column(3 columns), @plural_name="boxes", @collection=true>
+ >> User.reflections[:boxes].through_reflection
+ => #<ActiveRecord::Reflection::AssociationReflection:0x007faafddf4df0 @macro=:has_many, @name=:columns, @options={:order=>"position", :extend=>[]}, @active_record=User(14 columns), @plural_name="columns", @collection=true, @class_name="Column", @klass=Column(3 columns)>
+ >> User.reflections[:boxes].source_reflection_names
+ => [:box, :boxes]
+ >> User.reflections[:boxes].source_options
+ => {:order=>"position", :extend=>[]}
+ >> User.reflections[:boxes].through_options
+ => {:order=>"position", :extend=>[]}
+ >> User.reflections[:boxes].class_name
+ => "Box"
+
>> User.reflections[:columns].primary_key_column
=> #<ActiveRecord::ConnectionAdapters::PostgreSQLColumn:0x007fdcd859b868 @name="id", @sql_type="integer", @null=false, @limit=nil, @precision=nil, @scale=nil, @type=:integer, @default=nil, @primary=true, @coder=nil>
@@ -26,8 +41,6 @@
=> User(14 columns)
-
-
equalities = wheres.grep(Arel::Nodes::Equality)
>> ActiveRecord::Associations::AssociationScope.new(User.first.association(:columns)).scope.where_values
@@ -80,7 +93,7 @@
* Kill &block stuff.
-
+* Make association conditions use pure SQL. Avoid 100's of IDs.
View
4 lib/grouped_scope/arish/associations/association_scope.rb
@@ -55,9 +55,7 @@ def add_constraints(scope)
scope = scope.where(interpolate(condition))
end
else
- # GroupedScope changed this line.
- # constraint = table[key].eq(foreign_table[foreign_key])
- constraint = table[key].in(owner.group.ids)
+ constraint = table[key].eq(foreign_table[foreign_key])
if reflection.type
type = chain[i + 1].klass.base_class.name
View
3  lib/grouped_scope/arish/associations/builder/grouped_collection_association.rb
@@ -38,6 +38,9 @@ def find_ungrouped_reflection(model, name)
def ungrouped_reflection_options(ungrouped_reflection)
ungrouped_reflection.options.dup.tap do |options|
options[:class_name] = ungrouped_reflection.class_name
+ if ungrouped_reflection.source_reflection && options[:source].blank?
+ options[:source] = ungrouped_reflection.source_reflection.name
+ end
end
end
View
19 test/grouped_scope/has_many_through_test.rb
@@ -29,21 +29,20 @@ class GroupedScope::HasManyThroughTest < GroupedScope::TestCase
describe 'For grouped association' do
it 'scope to group' do
- raise @e2.group.departments(true).inspect
assert_sql(/"employee_id" IN \(#{@e1.id}, #{@e2.id}\)/) do
@e2.group.departments(true)
end
end
- # it 'scope count to group' do
- # assert_sql(/employee_id IN \(#{@e1.id},#{@e2.id}\)/) do
- # @e1.group.departments(true).count
- # end
- # end
- #
- # it 'have a group count equal to sum of seperate owner counts' do
- # assert_equal @e1.departments(true).count + @e2.departments(true).count, @e2.group.departments(true).count
- # end
+ it 'scope count to group' do
+ assert_sql(/"employee_id" IN \(#{@e1.id}, #{@e2.id}\)/) do
+ @e1.group.departments(true).count
+ end
+ end
+
+ it 'have a group count equal to sum of separate owner counts' do
+ assert_equal @e1.departments(true).count + @e2.departments(true).count, @e2.group.departments(true).count
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.