Skip to content

Commit 035aeaf

Browse files
committed
Extend query conditions guideline to cover equality
Passing conditions as a hash is always preferable to using an SQL fragment, regardless of whether the conditions are negated.
1 parent 03f02a3 commit 035aeaf

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

README.adoc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -858,12 +858,18 @@ User.find_by(email: email)
858858
User.find_by(first_name: 'Bruce', last_name: 'Wayne')
859859
----
860860

861-
=== Where Not [[where-not]]
861+
=== Hash conditions [[where-not]] [[hash-conditions]]
862862

863-
Favor the use of `where.not` over SQL.
863+
Favor passing conditions to `where` and `where.not` as a hash over using fragments of SQL.
864864

865865
[source,ruby]
866866
----
867+
# bad
868+
User.where("name = ?", name)
869+
870+
# good
871+
User.where(name: name)
872+
867873
# bad
868874
User.where("id != ?", id)
869875

0 commit comments

Comments
 (0)