Jump to content
NotionCommotion

What should be done with constraint only tables when using an ORM?

Recommended Posts

Instead of using MySQL's ENUM(), I typically create another table with the allowed values and have other tables include a FK to that table.

When using an ORM (i.e. Doctrine) should I create an entity for these?   It seems excessive, but if I don't, is there risk of the Doctrine deleting the tables?

Thanks

Share this post


Link to post
Share on other sites

I can't say I know Doctrine very well but I'm rather confident it will not delete tables that it is missing configuration for. It's one of those "principle of least astonishment" things.

If you need to manage the table or its data through code then set up an entity. If not then don't.

Share this post


Link to post
Share on other sites
4 hours ago, requinix said:

I can't say I know Doctrine very well but I'm rather confident it will not delete tables that it is missing configuration for. It's one of those "principle of least astonishment" things.

Yes, I expect you are technically right.  But if you follow their advice and use their schema-tool, I think it will.

Quote

Note that as you modify your entities' metadata during the development process, you'll need to update your database schema to stay in sync with the metadata. You can easily recreate the database using the following commands:


vendor/bin/doctrine orm:schema-tool:drop --force
vendor/bin/doctrine orm:schema-tool:create

Or you can use the update functionality:


vendor/bin/doctrine orm:schema-tool:update --force

The updating of databases uses a diff algorithm for a given database schema. This is a cornerstone of the Doctrine\DBAL package, which can even be used without the Doctrine ORM package.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.