Download the PHP package inlm/query-object without Composer
On this page you can find all versions of the php package inlm/query-object. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download inlm/query-object
More information about inlm/query-object
Files in inlm/query-object
Package query-object
Short Description Concept of Query Object for LeanMapper
License MIT
Informations about the package query-object
WARNING! This library is ABANDONED, use mibk/LeanMapperQuery instead. It contains all changes from this library and much more.
Lean Mapper Query
Lean Mapper Query is a concept of a query object for Lean Mapper library which helps to build complex queries using automatic joins (idea taken from NotORM library). Look at the suggested base classes. For Czech documentation have a look at the wiki.
Features
- it behaves as an
SQL
preprocessor, hence most SQL expressions are available - automatic joins using dot notation (
@book.tags.name
) - ability to query both repositories or entities
- support for implicit filters
Installation
It can be installed via Composer.
What does it do?
Suppose we have following repositories:
and following entities:
We build a query:
Now, if we want to get all books whose author's name is Karel, we have to do this:
Database query will look like this:
You can see it performs automatic joins via dot notation. It supports all types of relationships which are known to Lean Mapper.
It is very easy to use SQL functions. We can update query like this:
and change the database query into following:
Don't repeat yourself
You can extend Query
and define own methods.
Querying entities
It is also possible to query an entity property (currently only those properties with BelongsToMany
or HasMany
relationships). Let's build BaseEntity
:
Note that BaseEntity
extends Inlm\QueryObject\Entity
to make the following possible.
We have defined the find
method as protected
because with specifying the method name in $magicMethodsPrefixes
property you can query entities like this:
The magic method findTags
will eventually call your protected method find
with 'tags' as the 1 argument.
The resulting database query looks like this:
The first condition in where clause [tag].[id] IN (1, 2)
is taken from the entity traversing (tags are queried against this particular book entity's own tags).
What else you can do?
If we slightly modify our BaseRepository
and BaseEntity
we can simplify working with query objects. To achieve this look at the suggested base classes. It makes the following possible.
License
Copyright (c) 2013 Michal Bohuslávek
Licensed under the MIT license.