Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cartesian product number for one_to_one associations should be 0.

  • Loading branch information...
commit 45eb9fe8806db956e68f148d3fda5b033c53bda4 1 parent c3cbcc7
John Firebaugh authored
2  lib/sequel/model/associations.rb
View
@@ -859,7 +859,7 @@ def def_one_to_many(opts)
use_only_conditions = opts.include?(:graph_only_conditions)
only_conditions = opts[:graph_only_conditions]
conditions = opts[:graph_conditions]
- opts[:cartesian_product_number] ||= 1
+ opts[:cartesian_product_number] ||= opts[:one_to_one] ? 0 : 1
graph_block = opts[:graph_block]
opts[:eager_grapher] ||= proc do |ds, assoc_alias, table_alias|
ds = ds.graph(opts.associated_class, use_only_conditions ? only_conditions : cks.zip(cpks) + conditions, :select=>select, :table_alias=>assoc_alias, :join_type=>join_type, :implicit_qualifier=>table_alias, :from_self_alias=>ds.opts[:eager_graph][:master], &graph_block)
9 spec/integration/eager_loader_test.rb
View
@@ -685,6 +685,7 @@ class ::Ticket < Sequel::Model
end
class ::Book < Sequel::Model
one_to_many :first_page, :class=>:Page, :conditions=>{:page_number=>1}, :one_to_one=>true
+ one_to_many :second_page, :class=>:Page, :conditions=>{:page_number=>2}, :one_to_one=>true
end
INTEGRATION_DB.create_table!(:pages) do
@@ -722,4 +723,12 @@ class ::Page < Sequel::Model
bk1.first_page.should == @page1
bk2.first_page.should == @page3
end
+
+ it "should be eager graphable two at once" do
+ bk1, bk2 = Book.filter(:books__id=>[1,2]).eager_graph(:first_page, :second_page).all
+ bk1.first_page.should == @page1
+ bk1.second_page.should == @page2
+ bk2.first_page.should == @page3
+ bk2.second_page.should == @page4
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.