Browse files

Fix constraint generation when not using a proc or interpolated string

  • Loading branch information...
1 parent be4d716 commit a1ae2a3e496cfbd2be11d5618e60fa75d7e9eaaf @jeremyevans committed Sep 25, 2008
Showing with 11 additions and 1 deletion.
  1. +2 −0 CHANGELOG
  2. +2 −1 lib/sequel_core/schema/sql.rb
  3. +7 −0 spec/sequel_core/schema_spec.rb
View
2 CHANGELOG
@@ -1,5 +1,7 @@
=== HEAD
+* Fix constraint generation when not using a proc or interpolated string (jeremyevans)
+
* Make eager_graph respect associations' :order options (use :order_eager_graph=>false to disable) (jeremyevans)
* Cache negative lookup when eagerly loading many_to_one associations where no objects have an associated object (jeremyevans)
View
3 lib/sequel_core/schema/sql.rb
@@ -102,7 +102,8 @@ def constraint_definition_sql(constraint)
when :unique
sql << "UNIQUE #{literal(constraint[:columns])}"
else
- sql << "CHECK #{filter_expr(constraint[:check])}"
+ check = constraint[:check]
+ sql << "CHECK #{filter_expr((check.is_a?(Array) && check.length == 1) ? check.first : check)}"
end
sql
end
View
7 spec/sequel_core/schema_spec.rb
@@ -331,6 +331,13 @@
@db.sqls.should == ["CREATE TABLE cats (CHECK (price < 100))"]
end
+ specify "should accept hash constraints" do
+ @db.create_table(:cats) do
+ check :price=>100
+ end
+ @db.sqls.should == ["CREATE TABLE cats (CHECK (price = 100))"]
+ end
+
specify "should accept named constraint definitions" do
@db.create_table(:cats) do
integer :score

0 comments on commit a1ae2a3

Please sign in to comment.