Skip to content

Commit b720777

Browse files
author
Justin Dell
committed
provide more clarity to Where with Ranges
1 parent 4efd6de commit b720777

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

README.adoc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,9 +1061,9 @@ Use ranges instead of defining comparative conditions using a template for scala
10611061
[source,ruby]
10621062
----
10631063
# bad
1064-
User.where("created_at > ?", 30.days.ago).where("created_at < ?", 7.days.ago)
1065-
User.where("created_at > ? AND created_at < ?", 30.days.ago, 7.days.ago)
1066-
User.where("created_at > :start AND created_at < end", start: 30.days.ago, end: 7.days.ago)
1064+
User.where("created_at >= ?", 30.days.ago).where("created_at <= ?", 7.days.ago)
1065+
User.where("created_at >= ? AND created_at <= ?", 30.days.ago, 7.days.ago)
1066+
User.where("created_at >= :start AND created_at <= :end", start: 30.days.ago, end: 7.days.ago)
10671067
10681068
# good
10691069
User.where(created_at: 30.days.ago..7.days.ago)
@@ -1080,8 +1080,7 @@ User.where(created_at: 7.days.ago...) # also produces >=
10801080
User.where(created_at: ..7.days.ago) # inclusive: produces <=
10811081
User.where(created_at: ...7.days.ago) # exclusive: produces <
10821082
1083-
# okish - there is no range syntax that would denote inclusion on one end and
1084-
# exclusion on another.
1083+
# okish - there is no range syntax that would denote exclusion at the beginning of the range
10851084
Customer.where("purchases_count > :min AND purchases_count <= :max", min: 0, max: 5)
10861085
----
10871086

0 commit comments

Comments
 (0)