sequel 2.10.0 → 2.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +51 -1
- data/README.rdoc +2 -2
- data/Rakefile +2 -2
- data/doc/advanced_associations.rdoc +6 -18
- data/doc/release_notes/1.0.txt +38 -0
- data/doc/release_notes/1.1.txt +143 -0
- data/doc/release_notes/1.3.txt +101 -0
- data/doc/release_notes/1.4.0.txt +53 -0
- data/doc/release_notes/1.5.0.txt +155 -0
- data/doc/release_notes/2.0.0.txt +298 -0
- data/doc/release_notes/2.1.0.txt +271 -0
- data/doc/release_notes/2.10.0.txt +328 -0
- data/doc/release_notes/2.11.0.txt +215 -0
- data/doc/release_notes/2.2.0.txt +253 -0
- data/doc/release_notes/2.3.0.txt +88 -0
- data/doc/release_notes/2.4.0.txt +106 -0
- data/doc/release_notes/2.5.0.txt +137 -0
- data/doc/release_notes/2.6.0.txt +157 -0
- data/doc/release_notes/2.7.0.txt +166 -0
- data/doc/release_notes/2.8.0.txt +171 -0
- data/doc/release_notes/2.9.0.txt +97 -0
- data/lib/sequel_core/adapters/ado.rb +3 -0
- data/lib/sequel_core/adapters/db2.rb +0 -11
- data/lib/sequel_core/adapters/dbi.rb +0 -11
- data/lib/sequel_core/adapters/do.rb +0 -12
- data/lib/sequel_core/adapters/firebird.rb +21 -16
- data/lib/sequel_core/adapters/informix.rb +1 -11
- data/lib/sequel_core/adapters/jdbc.rb +1 -13
- data/lib/sequel_core/adapters/jdbc/h2.rb +3 -11
- data/lib/sequel_core/adapters/jdbc/mysql.rb +0 -17
- data/lib/sequel_core/adapters/jdbc/postgresql.rb +3 -15
- data/lib/sequel_core/adapters/mysql.rb +31 -27
- data/lib/sequel_core/adapters/odbc.rb +34 -28
- data/lib/sequel_core/adapters/openbase.rb +0 -11
- data/lib/sequel_core/adapters/oracle.rb +11 -9
- data/lib/sequel_core/adapters/postgres.rb +14 -17
- data/lib/sequel_core/adapters/shared/mssql.rb +6 -15
- data/lib/sequel_core/adapters/shared/mysql.rb +29 -14
- data/lib/sequel_core/adapters/shared/oracle.rb +4 -0
- data/lib/sequel_core/adapters/shared/postgres.rb +30 -35
- data/lib/sequel_core/adapters/shared/progress.rb +4 -0
- data/lib/sequel_core/adapters/shared/sqlite.rb +73 -13
- data/lib/sequel_core/adapters/sqlite.rb +8 -18
- data/lib/sequel_core/adapters/utils/date_format.rb +21 -0
- data/lib/sequel_core/{dataset → adapters/utils}/stored_procedures.rb +0 -0
- data/lib/sequel_core/{dataset → adapters/utils}/unsupported.rb +0 -0
- data/lib/sequel_core/core_ext.rb +1 -1
- data/lib/sequel_core/core_sql.rb +9 -4
- data/lib/sequel_core/database.rb +63 -62
- data/lib/sequel_core/dataset.rb +9 -4
- data/lib/sequel_core/dataset/convenience.rb +10 -9
- data/lib/sequel_core/dataset/prepared_statements.rb +1 -1
- data/lib/sequel_core/dataset/sql.rb +130 -36
- data/lib/sequel_core/schema/sql.rb +2 -2
- data/lib/sequel_core/sql.rb +44 -51
- data/lib/sequel_core/version.rb +1 -1
- data/lib/sequel_model/associations.rb +25 -17
- data/lib/sequel_model/base.rb +35 -7
- data/lib/sequel_model/caching.rb +1 -6
- data/lib/sequel_model/record.rb +23 -5
- data/lib/sequel_model/validations.rb +20 -5
- data/spec/adapters/firebird_spec.rb +6 -1
- data/spec/adapters/mysql_spec.rb +12 -0
- data/spec/adapters/postgres_spec.rb +2 -2
- data/spec/adapters/sqlite_spec.rb +81 -2
- data/spec/integration/dataset_test.rb +2 -2
- data/spec/integration/type_test.rb +12 -2
- data/spec/sequel_core/core_sql_spec.rb +46 -12
- data/spec/sequel_core/database_spec.rb +24 -12
- data/spec/sequel_core/dataset_spec.rb +82 -32
- data/spec/sequel_core/schema_spec.rb +16 -0
- data/spec/sequel_model/associations_spec.rb +89 -0
- data/spec/sequel_model/base_spec.rb +66 -0
- data/spec/sequel_model/eager_loading_spec.rb +32 -0
- data/spec/sequel_model/record_spec.rb +9 -9
- data/spec/sequel_model/spec_helper.rb +3 -0
- data/spec/sequel_model/validations_spec.rb +63 -3
- metadata +41 -4
data/CHANGELOG
CHANGED
@@ -1,3 +1,53 @@
|
|
1
|
+
=== 2.11.0 (2009-03-02)
|
2
|
+
|
3
|
+
* Optimize Model.[] by using static sql when possible, for a 30-40% speed increase (jeremyevans)
|
4
|
+
|
5
|
+
* Add Dataset#with_sql, which returns a clone of the datatset with static SQL (jeremyevans)
|
6
|
+
|
7
|
+
* Refactor Dataset#literal so it doesn't need to be overridden in subadapters, for a 20-25% performance increase (jeremyevans)
|
8
|
+
|
9
|
+
* Remove SQL::IrregularFunction, no longer used internally (jeremyevans)
|
10
|
+
|
11
|
+
* Allow String#lit to take arguments and return a SQL::PlaceholderLiteralString (jeremyevans)
|
12
|
+
|
13
|
+
* Add Model#set_associated_object, used by the many_to_one setter method, for easier overriding (jeremyevans)
|
14
|
+
|
15
|
+
* Allow use of database independent types when casting (jeremyevans)
|
16
|
+
|
17
|
+
* Give association datasets knowledge of the model object that created them and the related association reflection (jeremyevans)
|
18
|
+
|
19
|
+
* Make Dataset#select, #select_more, #order, #order_more, and #get take a block that yields a SQL::VirtualRow, similar to #filter (jeremyevans)
|
20
|
+
|
21
|
+
* Fix stored procedures in MySQL adapter when multiple arguments are used (clivecrous)
|
22
|
+
|
23
|
+
* Add :conditions association option, for easier filtering of associated objects (jeremyevans)
|
24
|
+
|
25
|
+
* Add :clone association option, for making clones of existing associations (jeremyevans)
|
26
|
+
|
27
|
+
* Handle typecasting invalid date strings (and possible other types) correctly (jeremyevans)
|
28
|
+
|
29
|
+
* Add :compress=>false option to MySQL adapter to turn off compression of client-server connection (tmm1)
|
30
|
+
|
31
|
+
* Set SQL_AUTO_IS_NULL=0 on MySQL connections, disable with :auto_is_null=>false (tmm1)
|
32
|
+
|
33
|
+
* Add :timeout option to MySQL adapter, default to 30 days (tmm1)
|
34
|
+
|
35
|
+
* Set MySQL encoding using Mysql#options so it works across reconnects (tmm1)
|
36
|
+
|
37
|
+
* Fully support blobs on SQLite (jeremyevans)
|
38
|
+
|
39
|
+
* Add String#to_sequel_blob, alias String#to_blob to that (jeremyevans)
|
40
|
+
|
41
|
+
* Fix default index names when a non-String or Symbol column is used (jeremyevans)
|
42
|
+
|
43
|
+
* Fix some ruby -w warnings (jeremyevans) (#259)
|
44
|
+
|
45
|
+
* Fix issues with default column values, table names, and quoting in the rename_column and drop_column support in shared SQLite adapter (jeremyevans)
|
46
|
+
|
47
|
+
* Add rename_column support to SQLite shared adapter (jmhodges)
|
48
|
+
|
49
|
+
* Add validates_inclusion_of validation (jdunphy)
|
50
|
+
|
1
51
|
=== 2.10.0 (2009-02-03)
|
2
52
|
|
3
53
|
* Don't use a default schema any longer in the shared PostgreSQL adapter (jeremyevans)
|
@@ -68,7 +118,7 @@
|
|
68
118
|
|
69
119
|
* Fix add_foreign_key for MySQL (jeremyevans, aphyr)
|
70
120
|
|
71
|
-
* Correctly literalize BigDecimal NaN and (+-)Infinity values (
|
121
|
+
* Correctly literalize BigDecimal NaN and (+-)Infinity values (jeremyevans) (#256)
|
72
122
|
|
73
123
|
* Make Sequel raise an Error if you attempt to subclass Sequel::Model before setting up a database connection (jeremyevans)
|
74
124
|
|
data/README.rdoc
CHANGED
@@ -228,7 +228,7 @@ You can also specify a custom WHERE clause using a string:
|
|
228
228
|
You can use parameters in your string, as well (ActiveRecord style):
|
229
229
|
|
230
230
|
posts.filter('(stamp < ?) AND (author != ?)', Date.today - 3, author_name)
|
231
|
-
posts.filter{|o| (o.stamp < Date.today
|
231
|
+
posts.filter{|o| (o.stamp < Date.today - 3) & ~{:author => author_name}} # same as above
|
232
232
|
|
233
233
|
Datasets can also be used as subqueries:
|
234
234
|
|
@@ -369,7 +369,7 @@ Models in Sequel are based on the Active Record pattern described by Martin Fowl
|
|
369
369
|
|
370
370
|
Model classes are defined as regular Ruby classes:
|
371
371
|
|
372
|
-
DB = Sequel.connect('sqlite
|
372
|
+
DB = Sequel.connect('sqlite://blog.db')
|
373
373
|
class Post < Sequel::Model
|
374
374
|
end
|
375
375
|
|
data/Rakefile
CHANGED
@@ -28,7 +28,7 @@ spec = Gem::Specification.new do |s|
|
|
28
28
|
s.version = VERS
|
29
29
|
s.platform = Gem::Platform::RUBY
|
30
30
|
s.has_rdoc = true
|
31
|
-
s.extra_rdoc_files = ["README.rdoc", "CHANGELOG", "COPYING"] + Dir["doc/*.rdoc"]
|
31
|
+
s.extra_rdoc_files = ["README.rdoc", "CHANGELOG", "COPYING"] + Dir["doc/*.rdoc"] + Dir['doc/release_notes/*.txt']
|
32
32
|
s.rdoc_options += RDOC_OPTS
|
33
33
|
s.summary = "The Database Toolkit for Ruby"
|
34
34
|
s.description = s.summary
|
@@ -73,7 +73,7 @@ end
|
|
73
73
|
Rake::RDocTask.new do |rdoc|
|
74
74
|
rdoc.rdoc_dir = "rdoc"
|
75
75
|
rdoc.options += RDOC_OPTS
|
76
|
-
rdoc.rdoc_files.add %w"README.rdoc CHANGELOG COPYING lib/**/*.rb doc/*.rdoc"
|
76
|
+
rdoc.rdoc_files.add %w"README.rdoc CHANGELOG COPYING lib/**/*.rb doc/*.rdoc doc/release_notes/*.txt"
|
77
77
|
end
|
78
78
|
|
79
79
|
### Website
|
@@ -152,11 +152,15 @@ otherwise modified:
|
|
152
152
|
end
|
153
153
|
Author.first.authorships_dataset.filter{|o| o.number < 10}.first
|
154
154
|
|
155
|
-
You can extend a dataset with a module easily with :extend
|
155
|
+
You can extend a dataset with a module easily with :extend. You can reference
|
156
|
+
the model object that created the association dataset via the dataset's
|
157
|
+
model_object method, and the related association reflection via the dataset's
|
158
|
+
association_reflection method:
|
156
159
|
|
157
160
|
module FindOrCreate
|
158
161
|
def find_or_create(vals)
|
159
|
-
first(vals) ||
|
162
|
+
first(vals) || association_reflection.associated_class. \
|
163
|
+
create(vals.merge(association_reflection[:key]=>model_object.id))
|
160
164
|
end
|
161
165
|
end
|
162
166
|
class Author < Sequel::Model
|
@@ -164,22 +168,6 @@ You can extend a dataset with a module easily with :extend:
|
|
164
168
|
end
|
165
169
|
Author.first.authorships_dataset.find_or_create(:name=>'Blah', :number=>10)
|
166
170
|
|
167
|
-
However, note that the dataset doesn't have any knowledge of the model object
|
168
|
-
that created it via the association, so if you want to use attributes of the
|
169
|
-
model object, you'll have to use a closure:
|
170
|
-
|
171
|
-
class Author < Sequel::Model
|
172
|
-
one_to_many :authorships, :dataset=>(proc do
|
173
|
-
key = pk
|
174
|
-
ds = Authorship.filter(:author_id=>key)
|
175
|
-
ds.meta_def(:find_or_create_by_name) do |name|
|
176
|
-
first(:name=>name) || Authorship.create(:name=>name, :author_id=>key)
|
177
|
-
end
|
178
|
-
ds
|
179
|
-
end)
|
180
|
-
end
|
181
|
-
Author.first.authorships_dataset.find_or_create_by_name('Bob')
|
182
|
-
|
183
171
|
===has_many :through associations
|
184
172
|
|
185
173
|
many_to_many handles the usual case of a has_many :through with a belongs_to in
|
@@ -0,0 +1,38 @@
|
|
1
|
+
=== New code organization
|
2
|
+
|
3
|
+
Sequel is now divided into two parts: sequel_core and sequel_model.
|
4
|
+
These two parts are distributed as two separate gems. The sequel gem
|
5
|
+
bundles sequel_core and sequel_model together. If you don't use
|
6
|
+
Sequel::Model in your code, you can just install and use sequel_core.
|
7
|
+
|
8
|
+
=== New model hooks implementation
|
9
|
+
|
10
|
+
The hooks implementation have been rewritten from scratch, is much
|
11
|
+
more robust and offers a few new features:
|
12
|
+
|
13
|
+
* More ways to define hooks: hooks can now be defined by supplying a
|
14
|
+
block or a method name, or by overriding the hook instance method.
|
15
|
+
|
16
|
+
* Inheritable hooks: Hooks can now be inherited, which means that you
|
17
|
+
can define general hooks in a model superclass, and use them in
|
18
|
+
subclasses. You can also define global hooks on Sequel::Model that
|
19
|
+
will be invoked for all model classes.
|
20
|
+
|
21
|
+
* Hook chains can be broken by returning false from within the hook.
|
22
|
+
|
23
|
+
* New after_initialize hook, invoked after instance initialization.
|
24
|
+
|
25
|
+
* The hook invocation order can no longer be changed. Hooks are
|
26
|
+
invoked in order of definition, from the top of the class hierarchy
|
27
|
+
(that is, from Sequel::Model) down to the specific class.
|
28
|
+
|
29
|
+
=== Miscellanea
|
30
|
+
|
31
|
+
* Removed deprecated adapter stubs, and all other deprecations in both
|
32
|
+
sequel_core and sequel_model.
|
33
|
+
|
34
|
+
* Fixed String#to_time to raise error correctly for invalid time
|
35
|
+
stamps.
|
36
|
+
|
37
|
+
* Fixed error behavior when parse_tree or ruby2ruby are not available.
|
38
|
+
|
@@ -0,0 +1,143 @@
|
|
1
|
+
=== DRY Sequel models
|
2
|
+
|
3
|
+
With the new Sequel release you no longer need to explicitly specify
|
4
|
+
the table
|
5
|
+
name for each model class, assuming your model name is the singular of
|
6
|
+
the
|
7
|
+
table name (just like in ActiveRecord or DataMapper):
|
8
|
+
|
9
|
+
class UglyBug < Sequel::Model
|
10
|
+
end
|
11
|
+
|
12
|
+
UglyBug.table_name #=> :ugly_bugs
|
13
|
+
|
14
|
+
=== New model validations and support for virtual attributes
|
15
|
+
|
16
|
+
Sequel model now include validation functionality which largly follows
|
17
|
+
the
|
18
|
+
validations offered in ActiveRecord. Validations can be checked
|
19
|
+
anytime by
|
20
|
+
calling Model#valid?, with validation errors accessible through
|
21
|
+
Model#errors:
|
22
|
+
|
23
|
+
class Item < Sequel::Model
|
24
|
+
validates_presence_of :name
|
25
|
+
end
|
26
|
+
|
27
|
+
my_item = Item.new
|
28
|
+
my_item.valid? #=> false
|
29
|
+
my_item.errors.full_messages #=> ["name is not present"]
|
30
|
+
|
31
|
+
The Model#save method has been changed to check for validity before
|
32
|
+
saving. If
|
33
|
+
the model instance is not valid, the #save method returns false
|
34
|
+
without saving
|
35
|
+
the instance. You can also bypass the validity test by calling
|
36
|
+
Model#save!
|
37
|
+
instead.
|
38
|
+
|
39
|
+
Model classes also now support virtual attributes, letting you assign
|
40
|
+
values to
|
41
|
+
any attribute (virtual or persistent) at initialization time:
|
42
|
+
|
43
|
+
class User < Sequel::Model
|
44
|
+
attr_accessor :password
|
45
|
+
end
|
46
|
+
|
47
|
+
u = User.new(:password => 'blah', ...)
|
48
|
+
u.password #=> 'blah'
|
49
|
+
|
50
|
+
Also, virtual attributes can be validated just like persistent
|
51
|
+
attributes.
|
52
|
+
|
53
|
+
=== Other changes (long list!)
|
54
|
+
|
55
|
+
* Added Model#reload as alias to Model#refresh.
|
56
|
+
|
57
|
+
* Changed Model.create to accept a block (#126).
|
58
|
+
|
59
|
+
* Fixed Model#initialize to accept nil values (#115).
|
60
|
+
|
61
|
+
* Added Model#update_with_params method with support for virtual
|
62
|
+
attributes and auto-filtering of unrelated parameters, and changed
|
63
|
+
Model.create_with_params to support virtual attributes (#128).
|
64
|
+
|
65
|
+
* Fixed Model.dataset to correctly set the dataset if using implicit
|
66
|
+
naming or inheriting the superclass dataset (thanks celldee).
|
67
|
+
|
68
|
+
* Finalized support for virtual attributes.
|
69
|
+
|
70
|
+
* Fixed Model#set to work with string keys (#143).
|
71
|
+
|
72
|
+
* Fixed Model.create to correctly initialize instances marked as new
|
73
|
+
(#135).
|
74
|
+
|
75
|
+
* Fixed Model#initialize to convert string keys into symbol keys. This
|
76
|
+
also fixes problem with validating objects initialized with string
|
77
|
+
keys (#136).
|
78
|
+
|
79
|
+
* Added Dataset#table_exists? convenience method.
|
80
|
+
|
81
|
+
* Changed Dataset#group_and_count to accept multiple columns (#134).
|
82
|
+
|
83
|
+
* Added Dataset#select_all method.
|
84
|
+
|
85
|
+
* Added Dataset#select_more, Dataset#order_more methods (#129).
|
86
|
+
|
87
|
+
* Fixed Dataset#count to work correctly for grouped datasets (#144).
|
88
|
+
|
89
|
+
* Fixed joining datasets using aliased tables (#140).
|
90
|
+
|
91
|
+
* Added support for UNSIGNED constraint, used in MySQL? (#127).
|
92
|
+
|
93
|
+
* Implemented constraint definitions inside Database#create_table.
|
94
|
+
|
95
|
+
* Enhanced Database.connect to accept options with string keys, so it
|
96
|
+
can now accept options loaded from YAML files. Database.connect also
|
97
|
+
automatically converts :username option into :user for compatibility
|
98
|
+
with existing YAML configuration files for AR and DataMapper.
|
99
|
+
|
100
|
+
* Changed ODBC::Database to support connection using driver and
|
101
|
+
database name, also added support for untitled columns in
|
102
|
+
ODBC::Dataset (thanks Leonid Borisenko).
|
103
|
+
|
104
|
+
* Changed MySQL adapter to support specifying socket option.
|
105
|
+
|
106
|
+
* Fixed MySQL adapter to correctly format foreign key definitions
|
107
|
+
(#123).
|
108
|
+
|
109
|
+
* Changed MySQL::Dataset to allow HAVING clause on ungrouped datasets,
|
110
|
+
and put HAVING clause before ORDER BY clause (#133).
|
111
|
+
|
112
|
+
* Changed mysql adapter to default to localhost if :host option is not
|
113
|
+
specified (#114).
|
114
|
+
|
115
|
+
* Added String#to_date. Updated mysql adapter to use String#to_date
|
116
|
+
for mysql date types (thanks drfreeze).
|
117
|
+
|
118
|
+
* Fixed postgres adapter to define PGconn#async_exec as alias to #exec
|
119
|
+
if not defined (for pure-ruby postgres driver).
|
120
|
+
|
121
|
+
* Changed postgres adapter to quote column references using double
|
122
|
+
quotes.
|
123
|
+
|
124
|
+
* Applied patch for oracle adapter: fix behavior of limit and offset,
|
125
|
+
transactions, #table_exists?, #tables and additional specs (thanks
|
126
|
+
Liming Lian #122).
|
127
|
+
|
128
|
+
* Added support additional field types in postgresql adapter (#146).
|
129
|
+
|
130
|
+
* Added support for date field types in postgresql adapter (#145).
|
131
|
+
|
132
|
+
* Added support for limiting and paginating datasets with fixed SQL,
|
133
|
+
e.g. using Database#fetch.
|
134
|
+
|
135
|
+
* Added new Dataset#from_self method that returns a dataset selecting
|
136
|
+
from the original dataset.
|
137
|
+
|
138
|
+
* Allow for additional filters on a grouped dataset (#119 and #120)
|
139
|
+
|
140
|
+
* Refactored Sequelizer to use Proc#to_sexp (method provided by r2r).
|
141
|
+
|
142
|
+
* Fixed bin/sequel to require sequel_model if available.
|
143
|
+
|
@@ -0,0 +1,101 @@
|
|
1
|
+
=== Better model associations
|
2
|
+
|
3
|
+
The latest release of sequel_model includes a new associations
|
4
|
+
functionality written by Jeremy Evans which replaces the old relations
|
5
|
+
code in previous versions. Please note that this version is not
|
6
|
+
completely backward-compatible and you should therefore upgrade with
|
7
|
+
caution.
|
8
|
+
|
9
|
+
The new implementation supports three kinds of relations: one_to_many,
|
10
|
+
many_to_one and many_to_many, which correspond to has_many, belongs_to
|
11
|
+
and has_and_belongs_to_many relations in ActiveRecord. In fact, the
|
12
|
+
new implementation includes aliases for ActiveRecord assocation macros
|
13
|
+
and is basically compatible with ActiveRecord conventions. It also
|
14
|
+
supports DRY implicit class name references. Here's a simple example:
|
15
|
+
|
16
|
+
class Author < Sequel::Model
|
17
|
+
has_many :books # equivalent to one_to_many
|
18
|
+
end
|
19
|
+
|
20
|
+
class Book < Sequel::Model
|
21
|
+
belongs_to :author # equivalent to many_to_one
|
22
|
+
has_and_belongs_to_many :categories # equivalent to many_to_many
|
23
|
+
end
|
24
|
+
|
25
|
+
class Category < Sequel::Model
|
26
|
+
has_and_belongs_to_many :books
|
27
|
+
end
|
28
|
+
|
29
|
+
These macros will create the following methods:
|
30
|
+
|
31
|
+
* Author#books, Author#add_book, Author#remove_book
|
32
|
+
* Book#author, Book#categories, Book#add_category,
|
33
|
+
Book#remove_category
|
34
|
+
* Category#books, Category#add_book, Category#remove_book
|
35
|
+
|
36
|
+
Unlike ActiveRecord, one_to_many and many_to_many association methods
|
37
|
+
return a dataset:
|
38
|
+
|
39
|
+
a = Author[1234]
|
40
|
+
a.books.sql #=> 'SELECT * FROM books WHERE (author_id = 1234)'
|
41
|
+
|
42
|
+
You can also tell Sequel to cache the association result set and
|
43
|
+
return it as an array:
|
44
|
+
|
45
|
+
class Author < Sequel::Model
|
46
|
+
has_many :books, :cache => true
|
47
|
+
end
|
48
|
+
|
49
|
+
Author[1234].books.class #=> Array
|
50
|
+
|
51
|
+
You can of course bypass the defaults and specify class names and key
|
52
|
+
names:
|
53
|
+
|
54
|
+
class Node < Sequel::Model
|
55
|
+
belongs_to :parent, :class => Node
|
56
|
+
belongs_to :session, :key => :producer_id
|
57
|
+
end
|
58
|
+
|
59
|
+
Another useful option is :order, which sets the order for the
|
60
|
+
association dataset:
|
61
|
+
|
62
|
+
class Author < Sequel::Model
|
63
|
+
has_many :books, :order => :title
|
64
|
+
end
|
65
|
+
|
66
|
+
Author[1234].books.sql #=> 'SELECT * FROM books WHERE (author_id =
|
67
|
+
1234) ORDER BY title'
|
68
|
+
|
69
|
+
More information about associations can be found in the Sequel
|
70
|
+
documentation.
|
71
|
+
|
72
|
+
=== Other changes
|
73
|
+
|
74
|
+
* Added configuration file for running specs (#186).
|
75
|
+
|
76
|
+
* Changed Database#drop_index to accept fixed arity (#173).
|
77
|
+
|
78
|
+
* Changed column definition sql to put UNSIGNED constraint before
|
79
|
+
unique in order to satisfy MySQL (#171).
|
80
|
+
|
81
|
+
* Enhanced MySQL adapter to support load data local infile_, added
|
82
|
+
compress option for mysql connection by default (#172).
|
83
|
+
|
84
|
+
* Fixed bug when inserting hashes in array tuples mode.
|
85
|
+
|
86
|
+
* Changed SQLite adapter to catch RuntimeError raised when executing a
|
87
|
+
statement and raise Error::InvalidStatement with the offending SQL and
|
88
|
+
error message (#188).
|
89
|
+
|
90
|
+
* Fixed Dataset#reverse to not raise for unordered dataset (#189).
|
91
|
+
|
92
|
+
* Added Dataset#unordered method and changed #order to remove order if
|
93
|
+
nil is specified (#190).
|
94
|
+
|
95
|
+
* Fixed reversing order of ASC expression (#164).
|
96
|
+
|
97
|
+
* Added support for :null => true option when defining table columns
|
98
|
+
(#192).
|
99
|
+
|
100
|
+
* Fixed Symbol#method_missing to accept variable arity (#185).
|
101
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
Eager loading for all types of associations:
|
2
|
+
|
3
|
+
Artist.eager(:albums).all
|
4
|
+
Album.eager(:artist, :genre, :tracks).all
|
5
|
+
Album.eager(:artist).eager(:genre).eager(:tracks).all
|
6
|
+
Album.filter(:year=>2008).eager(:artist).all
|
7
|
+
|
8
|
+
Eager loading supports cascading to an unlimited depth, and doesn't have
|
9
|
+
any aliasing issues:
|
10
|
+
|
11
|
+
Artist.eager(:albums=>:tracks).all
|
12
|
+
Artist.eager(:albums=>{:tracks=>:genre}).all
|
13
|
+
|
14
|
+
Unfortunately, eager loading comes at the expense of a small amount of
|
15
|
+
backward compatibility. If you were using uncached associations (the
|
16
|
+
default in sequel_model 0.5), they no longer work the same way. Now,
|
17
|
+
all associations act as if :cache=>true (which is now set for all
|
18
|
+
associations, so if you wrote a tool that worked with both cached and
|
19
|
+
uncached associations, it should still work).
|
20
|
+
|
21
|
+
One to many associations now populate the corresponding many to one
|
22
|
+
instance variable (even when eagerly loaded):
|
23
|
+
|
24
|
+
# Assuming: Album.one_to_many :tracks
|
25
|
+
album = Album.first
|
26
|
+
# This following code is only one query,
|
27
|
+
# not a query for the album and one for each track
|
28
|
+
album.tracks.each{|t| puts t.album.name}
|
29
|
+
|
30
|
+
ActiveRecord style has_many :through associations are now supported via
|
31
|
+
many_to_many. many_to_many will no longer select the entire result set,
|
32
|
+
just the columns of the associated table (and not the join table), so it
|
33
|
+
works for both has_and_belongs_to_many (simple join table) and has_many
|
34
|
+
:through (join table model) scenarios. If you want to include all or
|
35
|
+
part of the join table attributes, see the :select option for
|
36
|
+
many_to_many associations.
|
37
|
+
|
38
|
+
We reduced the number of gems from three (sequel, sequel_core,
|
39
|
+
sequel_model) to two (sequel, sequel_core). Basically, sequel_model is
|
40
|
+
now just sequel, and the old sequel gem metapackage is no longer. There
|
41
|
+
isn't a reason to have a gem metapackage for two gems when one
|
42
|
+
(sequel_model) depends on the other (sequel_core). This required a
|
43
|
+
version bump for the model part of sequel from 0.5.0.2 to 1.4.0 (since
|
44
|
+
the previous sequel gem version was 1.3).
|
45
|
+
|
46
|
+
Sequel 1.4.0 has fixes for 11 trackers issues, including fixes to the
|
47
|
+
MySQL and PostgreSQL adapters.
|
48
|
+
|
49
|
+
We have switched the source control repository for Sequel from Google
|
50
|
+
Code (which uses subversion) to github (which uses git). If you would
|
51
|
+
like to contribute to Sequel, please fork the github repository, make
|
52
|
+
your changes, and send a pull request. As before, posting patches on
|
53
|
+
the Google Code issue tracker is fine as well.
|