PHPackages                             eltharin/autoqb - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. eltharin/autoqb

ActiveSymfony-bundle[Database &amp; ORM](/categories/database)

eltharin/autoqb
===============

automaticquerybuilder Bundle for symfony

V1.1.0(11mo ago)049GPL-3.0PHP

Since Feb 8Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/eltharin/autoQb)[ Packagist](https://packagist.org/packages/eltharin/autoqb)[ RSS](/packages/eltharin-autoqb/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (4)Used By (0)

Symfony AutomaticQueryBuilder Bundle
====================================

[](#symfony-automaticquerybuilder-bundle)

[![Latest Stable Version](https://camo.githubusercontent.com/c1c6190f029379b77bacbe4f505c20bab747dc52dca7e9da380574f72365dc34/687474703a2f2f706f7365722e707567782e6f72672f656c74686172696e2f6175746f71622f76)](https://packagist.org/packages/eltharin/autoqb)[![Total Downloads](https://camo.githubusercontent.com/238ad9ff9e1825861b7b90f6d7d31cd4dacf078c2a1945fc1b47bcf97a79b8e2/687474703a2f2f706f7365722e707567782e6f72672f656c74686172696e2f6175746f71622f646f776e6c6f616473)](https://packagist.org/packages/eltharin/autoqb)[![Latest Unstable Version](https://camo.githubusercontent.com/175b9f1b3d00f3ade7fe82ca7e1a4fcce772b1a1b55cc899765402a618c24035/687474703a2f2f706f7365722e707567782e6f72672f656c74686172696e2f6175746f71622f762f756e737461626c65)](https://packagist.org/packages/eltharin/autoqb)[![License](https://camo.githubusercontent.com/f552561b761f1ac398904d25a20aad1d80a68379c6e7e2f5effc27fe5903faed/687474703a2f2f706f7365722e707567782e6f72672f656c74686172696e2f6175746f71622f6c6963656e7365)](https://packagist.org/packages/eltharin/autoqb)

Installation
------------

[](#installation)

- Require the bundle with composer:

```
composer require eltharin/autoqb
```

What is AutomaticQueryBuilder Bundle?
-------------------------------------

[](#what-is-automaticquerybuilder-bundle)

This bundle will create automatic custom queryBuilder (DQL) in repository.

Joins can be piloted by arguments without create one function each time joins are not the same.

How It Works ?
--------------

[](#how-it-works-)

First add AutoQbRepository trait in your repository.

This add getDQL() function and change findAll() :

```
use Eltharin\AutomaticQueryBuilderBundle\Repository\AutoQbRepository;

class MyEntityRepository extends ServiceEntityRepository
{
    use AutoQbRepository;

    ....
}
```

Now you can use it.
-------------------

[](#now-you-can-use-it)

Inline method
-------------

[](#inline-method)

In a service you can call your repository and ask link directly in getDQL function :

```
    $dql = $myRepository->getDQL();
```

Considering $myRepository is ClassTest1 Entity Repository, DQL query will be :

```
    SELECT classtest1
    FROM EltharinAutoQBTests\Entity\ClassTest1 classtest1
```

alias is tableName by default, or autoQBAlias property in repository or you can ether set in DQLOptions

you can pass a DqlOptions object to getDQL to ask relation :

```
    $dql = $myRepository->getDQL((new DqlOptions)->with('classtest1__classtest2'));
```

Considering ClassTest1 as a relation to entity ClassTest2, DQL query will be :

```
    SELECT classtest1, classtest1__classtest2
    FROM EltharinAutoQBTests\Entity\ClassTest1 classtest1
    LEFT JOIN classtest1.classtest2 classtest1__classtest2
```

you can ask a relation from relation without request middle, that's automatic :

```
    $dql = $myRepository->getDQL((new DqlOptions)->with('classtest1__classtest2__classtest3'));
```

Considering ClassTest1 as a relation to entity ClassTest2, DQL query will be :

```
    SELECT classtest1, classtest1__classtest2, classtest1__classtest2__classtest3
    FROM EltharinAutoQBTests\Entity\ClassTest1 classtest1
    LEFT JOIN classtest1.classtest2 classtest1__classtest2
    LEFT JOIN classtest1__classtest2.classtest3 classtest1__classtest2__classtest3
```

you find it's not enought automatic ? OK let's go for attributes

By properties attributes
------------------------

[](#by-properties-attributes)

You can also add attributes to your relations to make it more automatic, note you can have many attributes, the first compatible with your query will be taken :

We can add a relation to ClassTest4 in our entity, and add a AutoQBField attribute, with autolink at true, relation will be always taken.

```
    #[ORM\ManyToOne()]
    #[ORM\JoinColumn(nullable: false)]
    #[AutoQbField(autoLink: true)]
    private ?ClassTest4 $classtest4 = null;
```

now if we execute getDQL :

```
    $dql = $myRepository->getDQL();
```

Considering $myRepository is ClassTest1 Entity Repository, DQL query will be :

```
    SELECT classtest1, classtest1__classtest4
    FROM EltharinAutoQBTests\Entity\ClassTest1 classtest1
    LEFT JOIN classtest1.classtest4 classtest1__classtest4
```

---

You can change the jointype :

```
    #[ORM\ManyToOne()]
    #[ORM\JoinColumn(nullable: false)]
    #[AutoQbField(autoLink: true, joinType: 'inner')]
    private ?ClassTest4 $classtest4 = null;
```

now if we execute getDQL :

```
    $dql = $myRepository->getDQL();
```

Considering $myRepository is ClassTest1 Entity Repository, DQL query will be :

```
    SELECT classtest1, classtest1__classtest4
    FROM EltharinAutoQBTests\Entity\ClassTest1 classtest1
    INNER JOIN classtest1.classtest4 classtest1__classtest4
```

---

Automatic is good, but sometimes we want a relation only if root,

For example ClassTest1 have a manyToOne relation to ClassTest2 whitch have a manyToOne relation with ClassTest3

When we query ClassTest1 with ClassTest2 relation, we don't want have ClassTest3 automaticly but if we query ClassTest2 we want ever.

in ClassTest2 we add a AutoQbField attribute on ClassTest3 relation, add autolink and whenAlias arguments :

```
    #[ORM\ManyToOne()]
    #[ORM\JoinColumn(nullable: false)]
    #[AutoQbField(whenAlias: 'classtest2', autoLink: true)]
    private ?ClassTest3 $classtest3 = null;
```

```
    $dql = $class1Repository->getDQL((new DqlOptions)->with('classtest1__classtest2'));
```

will render DQL :

```
    SELECT classtest1, classtest1__classtest2
    FROM EltharinAutoQBTests\Entity\ClassTest1 classtest1
    LEFT JOIN classtest1.classtest2 classtest1__classtest2
```

and

```
    $dql = $class2Repository->getDQL();
```

will render DQL :

```
    SELECT classtest2, classtest2__classtest3
    FROM EltharinAutoQBTests\Entity\ClassTest2 classtest2
    LEFT JOIN classtest2.classtest3 classtest2__classtest3
```

now imagine you have a property in ClassTest2 named "visible". when you make a query on ClassTest1 you want have only classTest2 visible but in some circonstances, you want have all.

Remember, you can have many AutoQbField attributes :

```
    #[ORM\ManyToOne()]
    #[ORM\JoinColumn(nullable: false)]
    #[AutoQbField(relationAlias: 'classtest2All')]
    #[AutoQbField(conditionType: 'WITH', condition: '##alias##.visible = 1')]
    private ?ClassTest2 $classtest2 = null;
```

note we have set the relationAlias argument in first.

now :

```
    $dql = $class1Repository->getDQL((new DqlOptions)->with('classtest1__classtest2'));
```

will render DQL :

```
    SELECT classtest1, classtest1__classtest2
    FROM EltharinAutoQBTests\Entity\ClassTest1 classtest1
    LEFT JOIN classtest1.classtest2 classtest1__classtest2
        WITH classtest1__classtest2.visible = 1
```

and if we query the alias :

```
    $dql = $class1Repository->getDQL((new DqlOptions)->with('classtest1__classtest2All'));
```

will render DQL :

```
    SELECT classtest1, classtest1__classtest2All
    FROM EltharinAutoQBTests\Entity\ClassTest1 classtest1
    LEFT JOIN classtest1.classtest2 classtest1__classtest2All
```

you can also ask indexBy relation :

```
    #[ORM\ManyToOne()]
    #[ORM\JoinColumn(nullable: false)]
    #[AutoQbField(indexBy: 'idForIndexBy')]
    private ?ClassTest3 $classtest3 = null;
```

will render DQL :

```
    SELECT mySuperAlias8, mySuperAlias8__classtest3
    FROM EltharinAutoQBTests\Entity\ClassTest8 mySuperAlias8
    LEFT JOIN mySuperAlias8.classtest3 mySuperAlias8__classtest3
        INDEX BY mySuperAlias8__classtest3.idForIndexBy,
```

Now, IF you want more, you can make your own function in repository and call it :

```
    #[ORM\ManyToOne()]
    #[ORM\JoinColumn(nullable: false)]
    #[AutoQbField(callback: 'myCallbackInRepository')]
    private ?ClassTest4 $classtest4 = null;
```

```
    public function myCallbackInRepository(QueryBuilder $qb, AssociationMapping $assoc, AutoQbField $propertyAttribute, string $alias, string $subAlias, $from = [], $count = 0, ?array $with = [])
    {
        $qb->andWhere($alias . '.property = :something')->setParameter('something', 'something');
    }
```

```
    SELECT mySuperAlias8, mySuperAlias8__classtest4
    FROM EltharinAutoQBTests\Entity\ClassTest8 mySuperAlias8
    LEFT JOIN mySuperAlias8.classtest4 mySuperAlias8__classtest4
    WHERE mySuperAlias8.property = :something
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance52

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~64 days

Total

3

Last Release

336d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fff318a46a2e2f50b3a9fb70ee232f3dc317397c0b9dea4f0ed8ac37160dc471?d=identicon)[eltharin](/maintainers/eltharin)

---

Top Contributors

[![eltharin](https://avatars.githubusercontent.com/u/7547802?v=4)](https://github.com/eltharin "eltharin (5 commits)")

---

Tags

phpsymfonybundleweb

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/eltharin-autoqb/health.svg)

```
[![Health](https://phpackages.com/badges/eltharin-autoqb/health.svg)](https://phpackages.com/packages/eltharin-autoqb)
```

###  Alternatives

[omines/datatables-bundle

Symfony DataTables Bundle with native Doctrine ORM, Elastica and MongoDB support

2851.4M6](/packages/omines-datatables-bundle)[kucharovic/money-bundle

This bundle provides integration for Money library in your Symfony project.

2253.7k](/packages/kucharovic-money-bundle)[prezent/doctrine-translatable-bundle

Integrate the doctrine-translatable extension in Symfony

14698.4k5](/packages/prezent-doctrine-translatable-bundle)[farmatholin/segment-io-bundle

Segment.io php lib

11257.4k](/packages/farmatholin-segment-io-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
