Reply
How to override entity forum / board / topic / category
Replies: 1   Views: 1526  Subscribers: 2

Posted by Htb · 16-06-2014 - 11:01

Edited by Htb · 16-06-2014 - 15:42
Hello,

I want add a slug's field for my forum for forum / board / topic / category entity.

The problem is doctrine duplicate all (doctrine:schema:update --dump-sql) and i have the message "xxx.cc_forum_board" already exist.

My code 

­
// config.yml

orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true
        resolve_target_entities:
            Symfony\Component\Security\Core\User\UserInterface: Xxx\XxxUserBundle\Entity\XxxUser

// -           -             -             -               -              -                -              -            - 

ccdn_forum_forum:
    template:
        engine:               twig
        pager_theme:          CCDNComponentCommonBundle:Common:Paginator/twitter_bootstrap.html.twig
    entity:
        forum:
            #class:                CCDNForum\ForumBundle\Entity\Forum
            class:                Xxx\XxxForumBundle\Entity\XxxForum
        category:
            #class:                CCDNForum\ForumBundle\Entity\Category
            class:                Xxx\XxxForumBundle\Entity\XxxCategory
        board:
            #class:                CCDNForum\ForumBundle\Entity\Board
            class:                Xxx\XxxForumBundle\Entity\XxxBoard
        topic:
            #class:                CCDNForum\ForumBundle\Entity\Topic
            class:                Xxx\XxxForumBundle\Entity\XxxTopic
        post:
            class:                CCDNForum\ForumBundle\Entity\Post
        subscription:
            class:                CCDNForum\ForumBundle\Entity\Subscription
        registry:
            class:                CCDNForum\ForumBundle\Entity\Registry

// -             -              -                -               -              -                 -               -              - 

// My entity

namespace Xxx\XxxForumBundle\Entity;

use CCDNForum\ForumBundle\Entity\Board as BaseBoard;
use Doctrine\ORM\Mapping as ORM;

//use CCDNForum\ForumBundle\Entity\Model\Forum as AbstractForum;
//use Symfony\Component\Security\Core\SecurityContextInterface;


/**
 *
 * @category CCDNForum
 * @package  ForumBundle
 *
 * @author   Reece Fowell <[email protected]>
 * @license  http://opensource.org/licenses/MIT MIT
 * @version  Release: 2.0
 * @link     https://github.com/codeconsortium/CCDNForumForumBundle
 * 
 * @ORM\Entity
 * @ORM\Table(name="cc_forum_board")
 * 
 */
class XxxBoard extends BaseBoard
{
    
     /**
     * @var string
     * @ORM\Column(name="slug", type="string", length=255, nullable=true)
     *
     */
    private $slug;

    /**
     *
     * @access public
     */
    public function __construct()
    {
        parent::__construct();
    }

    
    /**
     * Get slug
     *
     * @return string
     */
    public function getSlug()
    {
        return $this->slug;
    }

    /**
     * Set slug
     *
     * @return string
     */
    public function setSlug($string)
    {
        $string = transliterator_transliterate("Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; Lower();", $string);
        $string = preg_replace('~[^\\pL\d]+~u', '-', $string);
        $this->slug = trim($string,"-");
        return $this->slug = $slug;
    }

   
}­
If i change the table name of my entity to "forum_board" (or forum/topic...) , my new table content all parent entity's field and my slug field added, but "cc_forum_board" parent table is also created! Thank you for your help. ­
C:\wamp\www\Symfony>php app/console doctrine:schema:update --dump-sql

CREATE TABLE cc_forum_board (
id INT AUTO_INCREMENT NOT NULL, 
fk_category_id INT DEFAULT NULL, 
fk_last_post_id INT DEFAULT NULL, 
name VARCHAR(255) NOT NULL, 
description LONGTEXT NOT NULL, 
cached_topic_count INT NOT NULL, 
cached_post_count INT NOT NULL, 
list_order_priority INT NOT NULL, 
read_authorised_roles LONGTEXT DEFAULT NULL COMMENT '(DC2Type:array)', 
topic_create_authorised_roles LONGTEXT DEFAULT NULL COMMENT '(DC2Type:array)', 
topic_reply_authorised_roles LONGTEXT DEFAULT NULL COMMENT '(DC2Type:array)', 
INDEX IDX_F7749CA47BB031D6 (fk_category_id), 
INDEX IDX_F7749CA4CD83D7D (fk_last_post_id), 
PRIMARY KEY(id)) 
DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;

CREATE TABLE forum_board (
id INT AUTO_INCREMENT NOT NULL, 
name VARCHAR(255) NOT NULL, 
description LONGTEXT NOT NULL, 
cached_topic_count INT NOT NULL, 
cached_post_count INT NOT NULL, 
list_order_priority INT NOT NULL, 
read_authorised_roles LONGTEXT DEFAULT NULL COMMENT '(DC2Type:array)', 
topic_create_authorised_roles LONGTEXT DEFAULT NULL COMMENT '(DC2Type:array)', 
topic_reply_authorised_roles LONGTEXT DEFAULT NULL COMMENT '(DC2Type:array)',
slug VARCHAR(255) DEFAULT NULL,
PRIMARY KEY(id)) 
DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;­
Same for forum_forum : ­
CREATE TABLE cc_forum_forum (
    id INT AUTO_INCREMENT NOT NULL, 
    name VARCHAR(255) NOT NULL, 
    read_authorised_roles LONGTEXT DEFAULT NULL COMMENT '(DC2Type:array)',
    UNIQUE INDEX UNIQ_2A09092E5E237E06 (name), 
    PRIMARY KEY(id)
) 
DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;

CREATE TABLE forum_forum (
    id INT AUTO_INCREMENT NOT NULL, 
    name VARCHAR(255) NOT NULL, 
    read_authorised_roles LONGTEXT DEFAULT NULL COMMENT '(DC2Type:array)', 
    slug VARCHAR(255) DEFAULT NULL, 
    UNIQUE INDEX UNIQ_9D5F181A5E237E06 (name), 
    PRIMARY KEY(id)
) 
DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;­

Posted by hetman · 28-07-2014 - 10:30

hi everyone

guys, could you please provide a proper algorithm to extend forum entities (topic, board, etc.)
My goal is to extend existing class and table

The only way I've found for doctrine 2 is to use mappedSuperclass

But I don't see any mappedSuperclass in your bundle­