Create new table using Pimcore DAO


#1

I’ve been working on implementing a Custom Persistent Model per this guide:

https://pimcore.com/docs/5.x/Development_Documentation/Extending_Pimcore/Custom_Persistent_Models.html

I’m wondering if there’s a way to have it create the table in the $tableName variable, if the table doesn’t already exist when saving? Most of the guides and things suggest creating this manually, but I’d like to automate that, if possible.


#2
if (!Db::get()->getSchemaManager()->tablesExist(['my_custom_table']) {
//CreateTable
}

Cheers


#3

Thank you for the reply and the code sample. Just to clarify, is that for the Doctrine approach, or for the Pimcore DOA? And perhaps it doesn’t matter?


#4

it doesn’t matter, it just checks if the table already exists. you can then go ahead and use the schema-manager to create the table, or you use the DAO thing and just execute the CREATE TABLE statement directly


#5

Got it to work. Thank you for pointing me in the right direction.