#where
, #and
, and #or
accept a raw SQL clause, with an optional placeholder (?
for MySQL/SQLite, $
for Postgres) to avoid SQL Injection.all
method, the selected fields will match the fields specified in the model unless the select
macro was used to customize the SELECT.?
in your query as placeholder. Checkout the Crystal DB Driver for documentation of the drivers.select_statement
macro allows you to customize the entire query, including the SELECT portion. This shouldn't be necessary in most cases, but allows you to craft more complex (i.e. cross-table) queries if needed:all
or first
for maximum flexibility:exists?
class method returns true
if a record exists in the table that matches the provided id or criteria, otherwise false
.Number
or String
, it will attempt to find a record with that primary key. If passed a Hash
or NamedTuple
, it will find the record that matches that criteria, similar to find_by
.exists?
method can also be used with the query builder.