aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README6
-rw-r--r--TODO2
-rw-r--r--lib/active_relation/primitives/attribute.rb10
-rw-r--r--spec/active_relation/unit/primitives/attribute_spec.rb22
-rw-r--r--spec/active_relation/unit/relations/deletion_spec.rb2
-rw-r--r--spec/active_relation/unit/relations/join_spec.rb10
-rw-r--r--spec/active_relation/unit/relations/relation_spec.rb2
-rw-r--r--spec/active_relation/unit/relations/update_spec.rb2
8 files changed, 28 insertions, 28 deletions
diff --git a/README b/README
index 54a698c768..87e9678df6 100644
--- a/README
+++ b/README
@@ -42,7 +42,7 @@ As you can see, the `relation` named `users` does not represent an individual qu
Following the Relational Algebra, Arel's interface uses some jargon that differs from standard SQL. For example, in order to add a `WHERE` clause to your relations, you use the `select` operation:
- users.select(users[:name].equals('amy')) # => SELECT * FROM users WHERE users.name = 'amy'
+ users.select(users[:name].eq('amy')) # => SELECT * FROM users WHERE users.name = 'amy'
What would, in SQL, be part of the `SELECT` clause is called here a `projection`:
@@ -50,12 +50,12 @@ What would, in SQL, be part of the `SELECT` clause is called here a `projection`
Joins are fairly straightforward:
- users.join(photos).on(users[:id].equals(photos[:user_id])) => SELECT * FROM users INNER JOIN photos ON users.id = photos.user_id
+ users.join(photos).on(users[:id].eq(photos[:user_id])) => SELECT * FROM users INNER JOIN photos ON users.id = photos.user_id
The best property of the Relational is compositionality, or closure under all operations. For example, to select and project:
users \
- .select(users[:name].equals('amy')) \
+ .select(users[:name].eq('amy')) \
.project(users[:id]) \
# => SELECT users.id FROM users WHERE users.name = 'amy'
diff --git a/TODO b/TODO
index 465fd5530d..4e7701917d 100644
--- a/TODO
+++ b/TODO
@@ -53,7 +53,7 @@ done:
. Audit SqlAlchemy for missing features
- Generalized denormalizations on any aggregation (count, yes, but also max, min, average)
- Remove operator overloading of << and <=> for joins. Make it just foo.join(bar) and foo.outer_join(bar).
-- Remove operator overloading of == for predicates. make it a.equals(b) (note lack of question mark).
+- Remove operator overloading of == for predicates. make it a.eq(b) (note lack of question mark).
- hookup more predicates (=, <=, =>)
- get some basic aggregations working: users.project(user[:points].max)
- Alias Table Names
diff --git a/lib/active_relation/primitives/attribute.rb b/lib/active_relation/primitives/attribute.rb
index fc857347fc..0ddbbb5cd4 100644
--- a/lib/active_relation/primitives/attribute.rb
+++ b/lib/active_relation/primitives/attribute.rb
@@ -62,23 +62,23 @@ module ActiveRelation
include Congruence
module Predications
- def equals(other)
+ def eq(other)
Equality.new(self, other)
end
- def less_than(other)
+ def lt(other)
LessThan.new(self, other)
end
- def less_than_or_equal_to(other)
+ def lteq(other)
LessThanOrEqualTo.new(self, other)
end
- def greater_than(other)
+ def gt(other)
GreaterThan.new(self, other)
end
- def greater_than_or_equal_to(other)
+ def gteq(other)
GreaterThanOrEqualTo.new(self, other)
end
diff --git a/spec/active_relation/unit/primitives/attribute_spec.rb b/spec/active_relation/unit/primitives/attribute_spec.rb
index bdd22721b3..a0f6cde8f7 100644
--- a/spec/active_relation/unit/primitives/attribute_spec.rb
+++ b/spec/active_relation/unit/primitives/attribute_spec.rb
@@ -16,7 +16,7 @@ module ActiveRelation
describe '#bind' do
it "manufactures an attribute with the relation bound and self as an ancestor" do
- derived_relation = @relation.select(@relation[:id].equals(1))
+ derived_relation = @relation.select(@relation[:id].eq(1))
@attribute.bind(derived_relation).should == Attribute.new(derived_relation, @attribute.name, :ancestor => @attribute)
end
@@ -95,33 +95,33 @@ module ActiveRelation
@attribute = Attribute.new(@relation, :name)
end
- describe '#equals' do
+ describe '#eq' do
it "manufactures an equality predicate" do
- @attribute.equals('name').should == Equality.new(@attribute, 'name')
+ @attribute.eq('name').should == Equality.new(@attribute, 'name')
end
end
- describe '#less_than' do
+ describe '#lt' do
it "manufactures a less-than predicate" do
- @attribute.less_than(10).should == LessThan.new(@attribute, 10)
+ @attribute.lt(10).should == LessThan.new(@attribute, 10)
end
end
- describe '#less_than_or_equal_to' do
+ describe '#lteq' do
it "manufactures a less-than or equal-to predicate" do
- @attribute.less_than_or_equal_to(10).should == LessThanOrEqualTo.new(@attribute, 10)
+ @attribute.lteq(10).should == LessThanOrEqualTo.new(@attribute, 10)
end
end
- describe '#greater_than' do
+ describe '#gt' do
it "manufactures a greater-than predicate" do
- @attribute.greater_than(10).should == GreaterThan.new(@attribute, 10)
+ @attribute.gt(10).should == GreaterThan.new(@attribute, 10)
end
end
- describe '#greater_than_or_equal_to' do
+ describe '#gteq' do
it "manufactures a greater-than or equal-to predicate" do
- @attribute.greater_than_or_equal_to(10).should == GreaterThanOrEqualTo.new(@attribute, 10)
+ @attribute.gteq(10).should == GreaterThanOrEqualTo.new(@attribute, 10)
end
end
diff --git a/spec/active_relation/unit/relations/deletion_spec.rb b/spec/active_relation/unit/relations/deletion_spec.rb
index 27d879e96f..71ddd8d820 100644
--- a/spec/active_relation/unit/relations/deletion_spec.rb
+++ b/spec/active_relation/unit/relations/deletion_spec.rb
@@ -15,7 +15,7 @@ module ActiveRelation
end
it 'manufactures sql deleting a selection relation' do
- Deletion.new(@relation.select(@relation[:id].equals(1))).to_sql.should be_like("
+ Deletion.new(@relation.select(@relation[:id].eq(1))).to_sql.should be_like("
DELETE
FROM `users`
WHERE `users`.`id` = 1
diff --git a/spec/active_relation/unit/relations/join_spec.rb b/spec/active_relation/unit/relations/join_spec.rb
index a0e94a5b65..515c9ce0f2 100644
--- a/spec/active_relation/unit/relations/join_spec.rb
+++ b/spec/active_relation/unit/relations/join_spec.rb
@@ -5,12 +5,12 @@ module ActiveRelation
before do
@relation1 = Table.new(:users)
@relation2 = Table.new(:photos)
- @predicate = @relation1[:id].equals(@relation2[:user_id])
+ @predicate = @relation1[:id].eq(@relation2[:user_id])
end
describe '==' do
before do
- @another_predicate = @relation1[:id].equals(1)
+ @another_predicate = @relation1[:id].eq(1)
@another_relation = Table.new(:cameras)
end
@@ -96,8 +96,8 @@ module ActiveRelation
end
it 'manufactures sql joining the two tables, merging any selects' do
- Join.new("INNER JOIN", @relation1.select(@relation1[:id].equals(1)),
- @relation2.select(@relation2[:id].equals(2)), @predicate).to_sql.should be_like("
+ Join.new("INNER JOIN", @relation1.select(@relation1[:id].eq(1)),
+ @relation2.select(@relation2[:id].eq(2)), @predicate).to_sql.should be_like("
SELECT `users`.`id`, `users`.`name`, `photos`.`id`, `photos`.`user_id`, `photos`.`camera_id`
FROM `users`
INNER JOIN `photos` ON `users`.`id` = `photos`.`user_id`
@@ -149,7 +149,7 @@ module ActiveRelation
end
it "keeps selects on the aggregation within the derived table" do
- Join.new("INNER JOIN", @relation1, @aggregation.select(@aggregation[:user_id].equals(1)), @predicate).to_sql.should be_like("
+ Join.new("INNER JOIN", @relation1, @aggregation.select(@aggregation[:user_id].eq(1)), @predicate).to_sql.should be_like("
SELECT `users`.`id`, `users`.`name`, `photo_count`.`user_id`, `photo_count`.`cnt`
FROM `users`
INNER JOIN (SELECT `photos`.`user_id`, COUNT(`photos`.`id`) AS `cnt` FROM `photos` WHERE `photos`.`user_id` = 1 GROUP BY `photos`.`user_id`) AS `photo_count`
diff --git a/spec/active_relation/unit/relations/relation_spec.rb b/spec/active_relation/unit/relations/relation_spec.rb
index b562ec2a2a..b5e204abcf 100644
--- a/spec/active_relation/unit/relations/relation_spec.rb
+++ b/spec/active_relation/unit/relations/relation_spec.rb
@@ -45,7 +45,7 @@ module ActiveRelation
describe Relation::Operations do
describe 'joins' do
before do
- @predicate = @relation[:id].equals(@relation[:id])
+ @predicate = @relation[:id].eq(@relation[:id])
end
describe '#join' do
diff --git a/spec/active_relation/unit/relations/update_spec.rb b/spec/active_relation/unit/relations/update_spec.rb
index 485c86372d..9053f292d6 100644
--- a/spec/active_relation/unit/relations/update_spec.rb
+++ b/spec/active_relation/unit/relations/update_spec.rb
@@ -36,7 +36,7 @@ module ActiveRelation
describe 'when the relation is a selection' do
before do
@update = Update.new(
- @relation.select(@relation[:id].equals(1)),
+ @relation.select(@relation[:id].eq(1)),
@relation[:name] => "nick".bind(@relation)
)
end