Query Builder
EntityQueryBuilder is Weaver ORM's fluent query API. It wraps Doctrine DBAL with full entity awareness: results are automatically hydrated into entity objects, global scopes are applied, and soft-delete filters are managed transparently.
Getting a QueryBuilder
Obtain a builder from a repository via query(), or from EntityWorkspace via createQueryBuilder():
<?php
// From a repository (recommended)
$users = $this->userRepository
->query()
->where('is_active', true)
->get();
// From the workspace
use Weaver\ORM\EntityWorkspace;
use App\Entity\Post;
$posts = $this->workspace
->createQueryBuilder(Post::class)
->where('status', 'published')
->get();
SELECT clauses
select(...$columns)
Replace the SELECT list. Calling it again replaces the previous selection.
<?php
$users = $this->userRepository
->query()
->select('id', 'name', 'email')
->get();
addSelect(...$columns)
Append columns to the current SELECT list without replacing it.
<?php
$qb = $this->productRepository->query()->select('id', 'name', 'price');
if ($this->isGranted('ROLE_MANAGER')) {
$qb->addSelect('cost_price', 'supplier_id');
}
$products = $qb->get();
selectRaw($expression, $bindings = [])
Add a raw SQL expression to the SELECT list.
<?php
$orders = $this->orderRepository
->query()
->select('id', 'customer_id', 'total')
->selectRaw('DATEDIFF(NOW(), created_at) AS age_days')
->where('status', 'pending')
->get();
WHERE clauses
All where*() methods combine conditions with AND by default. Use orWhere*() variants to combine with OR.
where($column, $value) — equality
<?php
$user = $this->userRepository
->query()
->where('email', 'alice@example.com')
->first();
where($column, $operator, $value) — with operator
Supported operators: =, !=, <>, <, <=, >, >=, LIKE, NOT LIKE.
<?php
$expensive = $this->productRepository
->query()
->where('price', '>', 100)
->where('stock', '>', 0)
->get();
orWhere($column, $value)
<?php
$results = $this->userRepository
->query()
->where('role', 'admin')
->orWhere('role', 'moderator')
->get();
whereIn($column, $values)
<?php
$users = $this->userRepository
->query()
->whereIn('status', ['active', 'trial'])
->get();
whereNotIn($column, $values)
<?php
$posts = $this->postRepository
->query()
->whereNotIn('status', ['draft', 'archived'])
->get();
whereNull($column) / whereNotNull($column)
<?php
// Users who have never logged in
$neverLoggedIn = $this->userRepository
->query()
->whereNull('last_login_at')
->get();
// Users with a verified email
$verified = $this->userRepository
->query()
->whereNotNull('email_verified_at')
->get();