sequel 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,4 +1,8 @@
1
- === HEAD
1
+ === 1.5.1 (2008-04-30)
2
+
3
+ * Fix Dataset#eager_graph when not all objects have associated objects (jeremyevans)
4
+
5
+ === 1.5.0 (2008-04-29)
2
6
 
3
7
  * Make the validation errors API compatible with Merb (Inviz)
4
8
 
data/Rakefile CHANGED
@@ -9,16 +9,14 @@ include FileUtils
9
9
  # Configuration
10
10
  ##############################################################################
11
11
  NAME = "sequel"
12
- VERS = "1.5.0"
13
- SEQUEL_CORE_VERS= "1.5.0"
12
+ VERS = "1.5.1"
13
+ SEQUEL_CORE_VERS= "1.5.1"
14
14
  CLEAN.include ["**/.*.sw?", "pkg/*", ".config", "doc/*", "coverage/*"]
15
15
  RDOC_OPTS = ["--quiet", "--line-numbers", "--inline-source"]
16
16
 
17
17
  ##############################################################################
18
18
  # RDoc
19
19
  ##############################################################################
20
- task :doc => [:rdoc]
21
-
22
20
  Rake::RDocTask.new do |rdoc|
23
21
  rdoc.rdoc_dir = "doc/rdoc"
24
22
  rdoc.options += RDOC_OPTS
@@ -70,16 +68,19 @@ end
70
68
  ##############################################################################
71
69
  # installation & removal
72
70
  ##############################################################################
71
+ desc "Install sequel gem"
73
72
  task :install do
74
73
  sh %{rake package}
75
74
  sh %{sudo gem install pkg/#{NAME}-#{VERS}}
76
75
  end
77
76
 
77
+ desc "Install sequel gem without docs"
78
78
  task :install_no_docs do
79
79
  sh %{rake package}
80
80
  sh %{sudo gem install pkg/#{NAME}-#{VERS} --no-rdoc --no-ri}
81
81
  end
82
82
 
83
+ desc "Uninstall sequel gem"
83
84
  task :uninstall => [:clean] do
84
85
  sh %{sudo gem uninstall #{NAME}}
85
86
  end
@@ -87,6 +88,7 @@ end
87
88
  ##############################################################################
88
89
  # gem and rdoc release
89
90
  ##############################################################################
91
+ desc "Upload sequel gem to rubyforge"
90
92
  task :release => [:package] do
91
93
  sh %{rubyforge login}
92
94
  sh %{rubyforge add_release sequel #{NAME} #{VERS} pkg/#{NAME}-#{VERS}.tgz}
@@ -272,10 +272,10 @@ module Sequel::Model::Associations::EagerLoading
272
272
  return if dependency_map.empty?
273
273
  # Don't clobber the instance variable array for *_to_many associations if it has already been setup
274
274
  dependency_map.keys.each do |ta|
275
- current.instance_variable_set("@#{alias_map[ta]}", []) unless type_map[ta] == :many_to_one || current.instance_variable_get("@#{alias_map[ta]}")
275
+ current.instance_variable_set("@#{alias_map[ta]}", type_map[ta] == :many_to_one ? :null : []) unless current.instance_variable_get("@#{alias_map[ta]}")
276
276
  end
277
277
  dependency_map.each do |ta, deps|
278
- rec = record_graph[ta]
278
+ next unless rec = record_graph[ta]
279
279
  key = rec.pk || rec.values.sort_by{|x| x[0].to_s}
280
280
  if cached_rec = records_map[ta][key]
281
281
  rec = cached_rec
@@ -545,4 +545,104 @@ describe Sequel::Model, "#eager_graph" do
545
545
  "SELECT genres.*, ag.album_id AS x_foreign_key_x FROM genres INNER JOIN ag ON (ag.album_id IN (1)) AND (ag.genre_id = genres.id)"
546
546
  ].should(include(MODEL_DB.sqls[1]))
547
547
  end
548
+
549
+ it "should handle no associated records for a single many_to_one association" do
550
+ ds = GraphAlbum.eager_graph(:band)
551
+ ds.sql.should == 'SELECT albums.id, albums.band_id, band.id AS band_id_0, band.vocalist_id FROM albums LEFT OUTER JOIN bands band ON (band.id = albums.band_id)'
552
+ def ds.fetch_rows(sql, &block)
553
+ yield({:id=>1, :band_id=>2, :band_id_0=>nil, :vocalist_id=>nil})
554
+ end
555
+ a = ds.all
556
+ a.should be_a_kind_of(Array)
557
+ a.size.should == 1
558
+ a.first.should be_a_kind_of(GraphAlbum)
559
+ a.first.values.should == {:id => 1, :band_id => 2}
560
+ a.first.instance_variable_get(:@band).should == :null
561
+ end
562
+
563
+ it "should handle no associated records for a single one_to_many association" do
564
+ ds = GraphAlbum.eager_graph(:tracks)
565
+ ds.sql.should == 'SELECT albums.id, albums.band_id, tracks.id AS tracks_id, tracks.album_id FROM albums LEFT OUTER JOIN tracks ON (tracks.album_id = albums.id)'
566
+ def ds.fetch_rows(sql, &block)
567
+ yield({:id=>1, :band_id=>2, :tracks_id=>nil, :album_id=>nil})
568
+ end
569
+ a = ds.all
570
+ a.should be_a_kind_of(Array)
571
+ a.size.should == 1
572
+ a.first.should be_a_kind_of(GraphAlbum)
573
+ a.first.values.should == {:id => 1, :band_id => 2}
574
+ a.first.tracks.should == []
575
+ end
576
+
577
+ it "should handle no associated records for a single many_to_many association" do
578
+ ds = GraphAlbum.eager_graph(:genres)
579
+ ds.sql.should == 'SELECT albums.id, albums.band_id, genres.id AS genres_id FROM albums LEFT OUTER JOIN ag ON (ag.album_id = albums.id) LEFT OUTER JOIN genres ON (genres.id = ag.genre_id)'
580
+ def ds.fetch_rows(sql, &block)
581
+ yield({:id=>1, :band_id=>2, :genres_id=>nil})
582
+ end
583
+ a = ds.all
584
+ a.should be_a_kind_of(Array)
585
+ a.size.should == 1
586
+ a.first.should be_a_kind_of(GraphAlbum)
587
+ a.first.values.should == {:id => 1, :band_id => 2}
588
+ a.first.genres.should == []
589
+ end
590
+
591
+ it "should handle missing associated records when loading multiple associations" do
592
+ ds = GraphAlbum.eager_graph(:genres, :tracks, :band)
593
+ ds.sql.should == 'SELECT albums.id, albums.band_id, genres.id AS genres_id, tracks.id AS tracks_id, tracks.album_id, band.id AS band_id_0, band.vocalist_id FROM albums LEFT OUTER JOIN ag ON (ag.album_id = albums.id) LEFT OUTER JOIN genres ON (genres.id = ag.genre_id) LEFT OUTER JOIN tracks ON (tracks.album_id = albums.id) LEFT OUTER JOIN bands band ON (band.id = albums.band_id)'
594
+ def ds.fetch_rows(sql, &block)
595
+ yield({:id=>1, :band_id=>2, :genres_id=>nil, :tracks_id=>3, :album_id=>1, :band_id_0=>nil, :vocalist_id=>nil})
596
+ yield({:id=>1, :band_id=>2, :genres_id=>nil, :tracks_id=>4, :album_id=>1, :band_id_0=>nil, :vocalist_id=>nil})
597
+ yield({:id=>1, :band_id=>2, :genres_id=>nil, :tracks_id=>5, :album_id=>1, :band_id_0=>nil, :vocalist_id=>nil})
598
+ yield({:id=>1, :band_id=>2, :genres_id=>nil, :tracks_id=>6, :album_id=>1, :band_id_0=>nil, :vocalist_id=>nil})
599
+ end
600
+ a = ds.all
601
+ a.should be_a_kind_of(Array)
602
+ a.size.should == 1
603
+ a.first.should be_a_kind_of(GraphAlbum)
604
+ a.first.values.should == {:id => 1, :band_id => 2}
605
+ a = a.first
606
+ a.tracks.should be_a_kind_of(Array)
607
+ a.tracks.size.should == 4
608
+ a.tracks.first.should be_a_kind_of(GraphTrack)
609
+ a.tracks.collect{|x|x[:id]}.should == [3,4,5,6]
610
+ a.instance_variable_get(:@band).should == :null
611
+ a.genres.should == []
612
+ end
613
+
614
+ it "should handle missing associated records when cascading eager loading for associations of associated models" do
615
+ ds = GraphTrack.eager_graph(:album=>{:band=>:members})
616
+ ds.sql.should == 'SELECT tracks.id, tracks.album_id, album.id AS album_id_0, album.band_id, band.id AS band_id_0, band.vocalist_id, members.id AS members_id FROM tracks LEFT OUTER JOIN albums album ON (album.id = tracks.album_id) LEFT OUTER JOIN bands band ON (band.id = album.band_id) LEFT OUTER JOIN bm ON (bm.band_id = band.id) LEFT OUTER JOIN members ON (members.id = bm.member_id)'
617
+ def ds.fetch_rows(sql, &block)
618
+ yield({:id=>2, :album_id=>2, :album_id_0=>nil, :band_id=>nil, :members_id=>nil, :band_id_0=>nil, :vocalist_id=>nil})
619
+ yield({:id=>3, :album_id=>3, :album_id_0=>3, :band_id=>3, :members_id=>nil, :band_id_0=>nil, :vocalist_id=>nil})
620
+ yield({:id=>4, :album_id=>4, :album_id_0=>4, :band_id=>2, :members_id=>nil, :band_id_0=>2, :vocalist_id=>6})
621
+ yield({:id=>5, :album_id=>1, :album_id_0=>1, :band_id=>4, :members_id=>5, :band_id_0=>4, :vocalist_id=>8})
622
+ yield({:id=>5, :album_id=>1, :album_id_0=>1, :band_id=>4, :members_id=>6, :band_id_0=>4, :vocalist_id=>8})
623
+ end
624
+ a = ds.all
625
+ a.should be_a_kind_of(Array)
626
+ a.size.should == 4
627
+ a.first.should be_a_kind_of(GraphTrack)
628
+ a.collect{|x|x[:id]}.should == [2,3,4,5]
629
+ a[0].instance_variable_get(:@album).should == :null
630
+ a[1].album.should be_a_kind_of(GraphAlbum)
631
+ a[1].album.values.should == {:id => 3, :band_id => 3}
632
+ a[1].album.instance_variable_get(:@band).should == :null
633
+ a[2].album.should be_a_kind_of(GraphAlbum)
634
+ a[2].album.values.should == {:id => 4, :band_id => 2}
635
+ a[2].album.band.should be_a_kind_of(GraphBand)
636
+ a[2].album.band.values.should == {:id => 2, :vocalist_id=>6}
637
+ a[2].album.band.members.should == []
638
+ a[3].album.should be_a_kind_of(GraphAlbum)
639
+ a[3].album.values.should == {:id => 1, :band_id => 4}
640
+ a[3].album.band.should be_a_kind_of(GraphBand)
641
+ a[3].album.band.values.should == {:id => 4, :vocalist_id=>8}
642
+ a[3].album.band.members.size.should == 2
643
+ a[3].album.band.members.first.should be_a_kind_of(GraphBandMember)
644
+ a[3].album.band.members.first.values.should == {:id => 5}
645
+ a[3].album.band.members.last.should be_a_kind_of(GraphBandMember)
646
+ a[3].album.band.members.last.values.should == {:id => 6}
647
+ end
548
648
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: sequel
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.5.0
7
- date: 2008-04-29 00:00:00 -07:00
6
+ version: 1.5.1
7
+ date: 2008-04-30 00:00:00 -07:00
8
8
  summary: "The Database Toolkit for Ruby: Model Classes"
9
9
  require_paths:
10
10
  - lib
@@ -89,5 +89,5 @@ dependencies:
89
89
  requirements:
90
90
  - - "="
91
91
  - !ruby/object:Gem::Version
92
- version: 1.5.0
92
+ version: 1.5.1
93
93
  version: