Add column to table without related property on its entity #5398

Closed
opened 2026-01-22 15:06:27 +01:00 by admin · 3 comments
Owner

Originally created by @koemeet on GitHub (Jan 30, 2017).

Originally assigned to: @Ocramius on GitHub.

I wanted to implement multi tenancy for an existing project using Doctrine without changing their metadata files or subclassing their models to add an extra field. Would it be easy/possible to extend Doctrine in a way that it adds a specific column to the table of an entity without having a property on that entity that represents that column? This way the models stay intact and you could use a SQL filter to filter down on that column to achieve multi tenancy.

Are there people who implemented something similar or have tips on how this can be done with Doctrine ORM?

Originally created by @koemeet on GitHub (Jan 30, 2017). Originally assigned to: @Ocramius on GitHub. I wanted to implement multi tenancy for an existing project using Doctrine without changing their metadata files or subclassing their models to add an extra field. Would it be easy/possible to extend Doctrine in a way that it adds a specific column to the table of an entity without having a property on that entity that represents that column? This way the models stay intact and you could use a SQL filter to filter down on that column to achieve multi tenancy. Are there people who implemented something similar or have tips on how this can be done with Doctrine ORM?
admin added the ImprovementCan't FixQuestion labels 2026-01-22 15:06:27 +01:00
admin closed this issue 2026-01-22 15:06:28 +01:00
Author
Owner

@Ocramius commented on GitHub (Jan 30, 2017):

You'd just add a column in a manual migration: this is not something that can be done in the metadata API, since every field expects a matching reflection field.

@Ocramius commented on GitHub (Jan 30, 2017): You'd just add a column in a manual migration: this is not something that can be done in the metadata API, since every field expects a matching reflection field.
Author
Owner

@koemeet commented on GitHub (Jan 30, 2017):

Thanks for the fast response, wow! 😄

@koemeet commented on GitHub (Jan 30, 2017): Thanks for the fast response, wow! 😄
Author
Owner

@lcobucci commented on GitHub (Jan 31, 2017):

@steffenbrem sometime ago I've created something based on Doctrine\DBAL\Sharding\PoolingShardConnection and a custom Doctrine\DBAL\Sharding\ShardChoser\ShardChoser to implement multitenancy but I had a different schema for each tenant (with the same mapping) and everything worked just fine.

@lcobucci commented on GitHub (Jan 31, 2017): @steffenbrem sometime ago I've created something based on `Doctrine\DBAL\Sharding\PoolingShardConnection` and a custom `Doctrine\DBAL\Sharding\ShardChoser\ShardChoser` to implement multitenancy but I had a different schema for each tenant (with the same mapping) and everything worked just fine.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5398