There are a number of conditional operations in Spot that can be used to build more complex queries without obtuse query builder syntax or long namespaced constants.
A Query Example
Accepted Query Values
Spot can use many different types of values in the query builder, and will automatically do the right thing with them.
Scalar values like normal strings, integers, and floats will be handled normally:
DateTime objects can be used as query values, and will be automatically
converted to the native database driver’s required format.
Array values passed to Spot’s query builder will result in automatic “IN” clause.
If a value is
null, Spot will use the proper SQL syntax:
If a value is boolean
false, Spot will use the proper SQL syntax
according to the database adapter you are using:
There is no substitute for the power and expressiveness of SQL. While ORMs like Spot are very nice to use, if you need to do complex queries, it’s best to just use custom queries with the SQL you know and love. This is why Spot’s query builder is fairly simple compared to other ORMs, and doesn’t support things like subqueries, etc.
Spot provides a
query method that allows you to run custom SQL, and load the
results into a normal collection of entity objects. This way, you can easily run
custom SQL queries with all the same ease of use and convenience as the
built-in finder methods and you won’t have to do any special handling.
Using Custom SQL
Using Query Parameters
Using Named Placeholders
Joins are currently not enabled by Spot’s query builder. The Doctine DBAL query builder does provide full support for them, so they may be enabled in the future.