Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$conditions field for the OneToMany Join #11343

Open
dozsan opened this issue Mar 6, 2024 · 0 comments
Open

$conditions field for the OneToMany Join #11343

dozsan opened this issue Mar 6, 2024 · 0 comments

Comments

@dozsan
Copy link

dozsan commented Mar 6, 2024

Feature Request

Q A
New Feature yes
RFC yes
BC Break no

Summary

I would like to untangle the joins with a solution like $conditions in QueryBuilder.
I've often run into the problem that it would be nice to be able to attach a table without always having to create an attachment table, this example is a problem for me apart from the names.

class OneToManyEntity {
    #[ORM\Id, ORM\GeneratedValue, ORM\Column]
    private ?int $id = null;

    #[ORM\OneToMany(
        targetEntity: Storage::class,
        conditions: [
            'target.entityClass' => 'etc...' OR
            'target.entityClass' => OneToManyEntity::class OR -> sql example below
            'target.entityClass' => 'self.other colums' OR
            'self.other colum' => FooBarEnumClass::VALUE
            Or even Doctrine\ORM\Query\Exy\Expr\Comparison or something similar
        ]
    )]
    private Collection $storages;
    
    public function __construct()
    {
        $this->storages = new ArrayCollection();
    }
}

SQL example:
SELECT * FROM OneToManyEntity LEFT JOIN Storage ON (OneToManyEntity.id = Storage.entityId AND Storage.entityClass = 'App\Entity\OneToManyEntity')

The "target" and "self" in the conditions array would refer to the table in question.
In the case of OneToManyEntity, the query builder would substitute the name of the storage table for "target" and the name of the OneToManyEntity table for "self".

Of course this would be useful for multiple tables, like in my case where I have about 10 tables connected to the Storage table, but I don't want to put 10 separate ids on the Storage table

Which is a big question how "mappedBy" and "inversedBy" could be used, but I guess not :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant