OroPlatform Forums

Covering OroPlatform topics, including community updates and company announcements.

Forums Forums OroPlatform OroPlatform – Programming Questions How to add attachements to custom entity

This topic contains 3 replies, has 2 voices, and was last updated by  Yurii Muratov 8 years, 6 months ago.

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #33964

    Neal Vanmeert
    Participant

    Hi, I created a custom bundle with a custom entity.

    In my migrations I added AttachmentExtensionAwareInterface

    /**
    * {@inheritdoc}
    */
    public function up(Schema $schema, QueryBag $queries)
    {
    $table = $schema->createTable('emuse_businesscard');
    $table->addColumn('id', 'integer', ['autoincrement' => true]);
    $table->addColumn('owner_id', 'integer', ['notnull' => false]);
    $table->addColumn('createdAt', 'datetime', []);
    $table->addColumn('updatedAt', 'datetime', ['notnull' => false]);
    $table->setPrimaryKey(['id']);
    $table->addIndex(['owner_id'], 'IDX_2F32390A7E3C61F9', []);
    self::addUploadToBusinessCard($schema, $this->attachmentExtension);
    }

    /**
    * @param Schema $schema
    * @param AttachmentExtension $attachmentExtension
    */
    public static function addUploadToBusinessCard(Schema $schema, AttachmentExtension $attachmentExtension)
    {
    $attachmentExtension->addImageRelation(
    $schema,
    'emuse_businesscard',
    'businesscard_upload',
    [],
    2,
    1024,
    768
    );
    }

    But when I run my migrations I get an error:

    php app/console oro:migration:load --dry-run --show-queries

    An extend field "businesscard_upload" cannot be added to non extend entity "eMuse\Bundle\BusinessCardBundle\Entity\BusinessCardEntity".

    How can I make my entity extendable, or what is the best way to add an attachement ?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #33965

    Yurii Muratov
    Participant

    Hi, @neal_vanmeert.

    To make your entity extenable, your entity should extends from empty class eMuse\Bundle\BusinessCardBundle\Model\ExtendBusinessCardEntity.
    And another thing, your entity should be configurable (should have @Config annotation).

    For example, please look how it was done for Account entity https://github.com/orocrm/crm/blob/master/src/OroCRM/Bundle/AccountBundle/Entity/Account.php.
    Here, at line 28 we have Config annotation and at line 60 we have extends from empty OroCRM\Bundle\AccountBundle\Model\ExtendAccount class.

    #33966

    Neal Vanmeert
    Participant

    Hi, This indeed helped, I don’t really understand how an extend of an empty class makes this work. Is there info to be found ?

    We are interested in OroCRM and creating modules for it, but we are lacking information to really create quality code.

    #33967

    Yurii Muratov
    Participant

    Hi, @neal_vanmeert.
    We have some documentation about extend entities here http://oroinc.com/orocrm/doc/current/book/entities

Viewing 3 replies - 1 through 3 (of 3 total)

The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.

Back to top