Skip to content

Commit

Permalink
Merge Dataset::FROM_SELF_KEEP_OPTS into Dataset::NON_SQL_OPTIONS
Browse files Browse the repository at this point in the history
While used in different places, these were used pretty much for the
same things, and in both cases where one was used, the values from
the other should have been taken into account.  Breaks backwards
compatibility slightly, but it's unlikely anyone is using it.
  • Loading branch information
jeremyevans committed Dec 10, 2009
1 parent 73e3f1f commit aeaa188
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
=== HEAD

* Merge Dataset::FROM_SELF_KEEP_OPTS into Dataset::NON_SQL_OPTIONS (jeremyevans)

* Add Database#remove_servers for removing servers from the pool on the fly (jeremyevans)

* When disconnecting servers, if there are any connections to the server currently in use, schedule them to be disconnected (jeremyevans)
Expand Down
2 changes: 1 addition & 1 deletion lib/sequel/dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Dataset

# Which options don't affect the SQL generation. Used by simple_select_all?
# to determine if this is a simple SELECT * FROM table.
NON_SQL_OPTIONS = [:server, :defaults, :overrides]
NON_SQL_OPTIONS = [:server, :defaults, :overrides, :graph, :eager_graph, :graph_aliases]

NOTIMPL_MSG = "This method must be overridden in Sequel adapters".freeze
WITH_SUPPORTED=:select_with_sql
Expand Down
7 changes: 2 additions & 5 deletions lib/sequel/dataset/query.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
module Sequel
class Dataset

FROM_SELF_KEEP_OPTS = [:graph, :eager_graph, :graph_aliases]

# Adds an further filter to an existing filter using AND. If no filter
# exists an error is raised. This method is identical to #filter except
# it expects an existing filter.
Expand Down Expand Up @@ -148,7 +145,7 @@ def from(*source)
# ds.from_self(:alias=>:foo).sql #=> "SELECT * FROM (SELECT id, name FROM items ORDER BY name) AS foo"
def from_self(opts={})
fs = {}
@opts.keys.each{|k| fs[k] = nil unless FROM_SELF_KEEP_OPTS.include?(k)}
@opts.keys.each{|k| fs[k] = nil unless NON_SQL_OPTIONS.include?(k)}
clone(fs).from(opts[:alias] ? as(opts[:alias]) : self)
end

Expand Down Expand Up @@ -263,7 +260,7 @@ def order(*columns, &block)
columns += Array(Sequel.virtual_row(&block)) if block
clone(:order => (columns.compact.empty?) ? nil : columns)
end
alias_method :order_by, :order
alias order_by order

# Returns a copy of the dataset with the order columns added
# to the existing order.
Expand Down
9 changes: 9 additions & 0 deletions spec/core/dataset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1534,19 +1534,28 @@ def fetch_rows(sql)
before do
@ds = Sequel::Dataset.new(nil).from(:test).select(:name).limit(1)
end

specify "should set up a default alias" do
@ds.from_self.sql.should == 'SELECT * FROM (SELECT name FROM test LIMIT 1) AS t1'
end

specify "should modify only the new dataset" do
@ds.from_self.select(:bogus).sql.should == 'SELECT bogus FROM (SELECT name FROM test LIMIT 1) AS t1'
end

specify "should use the user-specified alias" do
@ds.from_self(:alias=>:some_name).sql.should == 'SELECT * FROM (SELECT name FROM test LIMIT 1) AS some_name'
end

specify "should use the user-specified alias for joins" do
@ds.from_self(:alias=>:some_name).inner_join(:posts, :alias=>:name).sql.should == \
'SELECT * FROM (SELECT name FROM test LIMIT 1) AS some_name INNER JOIN posts ON (posts.alias = some_name.name)'
end

specify "should not options such as server" do
@ds.server(:blah).from_self(:alias=>:some_name).opts[:server].should == :blah
end

end

context "Dataset#join_table" do
Expand Down

0 comments on commit aeaa188

Please sign in to comment.