zikula-modules / DizkusModule

Official repository for Dizkus, a fully integrated forum solution for Zikula 1.4+
21 stars 7 forks source link

Change all entity id fields to id #294

Closed Kaik closed 7 years ago

Kaik commented 8 years ago

Most of the entities have entity name in id field for example topic_id, forum_id etc... this can/should be refactored to just id.

craigh commented 8 years ago

changing the actual column name in the DB is more difficult than you might think. I tried to do it in blocks (content -> properties) and it killed all upgrades to the 1.4.2 release. So don't use the SchemaTool. You will probably have to achieve it with manual SQL. Another option is to leave the DB alone and only change the property names in the object (have to then notate the column name in the entity def).

Kaik commented 8 years ago

Ok good to know. I will use SQL I have used it before in InterCom module and I was using Dizkus as an example it worked. Column names were changed using SQL and SchemaTool update was called at the end - I believe it is called only to refresh some internal doctrine mappings - and it is not used to change any column name.

...
        $sql = 'UPDATE intercom SET msg_outbox = NOT msg_outbox';
        $stmt = $connection->prepare($sql);
        $stmt->execute();
...
        try {
            $this->schemaTool->update(['Zikula\IntercomModule\Entity\MessageEntity']);
        } catch (Exception $e) {
            $this->addFlash('error', $e);
            return false;
        }
...

I do not yet know when (which version) I will do this. I need to think about it.

Kaik commented 7 years ago

This is mostly done in a way you described using name in colum def.