This topic contains 1 reply, has 1 voice, and was last updated by zhex900 7 years ago.
- Topic
Hi,
I have created a custom entity called EventName. EventName have an one to many relationship with calendar events (OroCalendarBundle). For example an EventName called Birthday Parties can have many calendar events.
EventName have one to many relationship with CalendarEvents.
CalendarEvents have many to one relationship with EventName.Please let me know what I am doing is on the right track. My goal is to add EventName from a Calendar Event. Also add Calendar Event in EventName.
EventName Entity file
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980// EventNameBundle/Entity/EventName.php/*** Events storage** @var ArrayCollection $events** @ORM\OneToMany(targetEntity="Oro\Bundle\CalendarBundle\Entity\CalendarEvent", mappedBy="eventname")* @ORM\JoinTable(name="orocrm_eventname_to_event")* @ConfigField(* defaultValues={* "merge"={* "display"=true* },* "importexport"={* "order"=50,* "short"=true* }* }* )*/protected $events;/*** Add specified event** @param CalendarEvent $event** @return EventName*/public function addEvent(CalendarEvent $event){if (!$this->getEvents()->contains($event)) {$this->getEvents()->add($event);// $event->addEvent($this);}return $this;}/*** Get events collection** @return Collection|CalendarEvent[]*/public function getEvents(){return $this->events;}/*** Set events collection** @param Collection $events** @return EventName*/public function setEvents(Collection $events){$this->$events = $events;return $this;}/*** Remove specified event** @param CalendarEvent $event** @return EventName*/public function removeEvent(CalendarEvent $event){if ($this->getEvents()->contains($event)) {$this->getEvents()->removeElement($event);//$event->removeAccount($this);}return $this;}EventName Migration file
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576<?php// EventNameBundle/Migrations/Schema/v2_1/OroEventNameBundle.phpnamespace CampusCRM\EventNameBundle\Migrations\Schema\v2_1;use Doctrine\DBAL\Schema\Schema;use Oro\Bundle\MigrationBundle\Migration\Migration;use Oro\Bundle\MigrationBundle\Migration\QueryBag;use Oro\Bundle\EntityBundle\EntityConfig\DatagridScope;use Oro\Bundle\EntityExtendBundle\EntityConfig\ExtendScope;use Oro\Bundle\SecurityBundle\Migrations\Schema\UpdateOwnershipTypeQuery;class EventNameBundle implements Migration{/*** @inheritdoc* @SuppressWarnings(PHPMD.ExcessiveMethodLength)*/public function up(Schema $schema, QueryBag $queries){// @codingStandardsIgnoreStart/** Generate table eventname **/$table = $schema->createTable('orocrm_eventname');$table->addColumn('id', 'integer', ['autoincrement' => true]);$table->addColumn('user_owner_id', 'integer', ['notnull' => false]);$table->addColumn('name', 'string', ['length' => 255]);$table->addColumn('createdAt', 'datetime', []);$table->addColumn('updatedAt', 'datetime', []);$table->setPrimaryKey(['id']);$table->addIndex(['user_owner_id'], 'IDX_7166D3719EB185F9', []);$table->addIndex(['name'], 'eventname_name_idx', []);$table->addColumn('organization_id', 'integer', ['notnull' => false]);$table->addIndex(['organization_id'], 'IDX_7166D37132C8A3DE', []);$table->addForeignKeyConstraint($schema->getTable('oro_organization'),['organization_id'],['id'],['onDelete' => 'SET NULL', 'onUpdate' => null]);//Add organization fields to ownership entity config$queries->addQuery(new UpdateOwnershipTypeQuery('CampusCRM\EventNameBundle\Entity\EventName',['organization_field_name' => 'organization','organization_column_name' => 'organization_id']));/** End of generate table eventname **//** Generate table orocrm_eventname_to_event **/$table = $schema->createTable('orocrm_eventname_to_event');$table->addColumn('eventname_id', 'integer', []);$table->addColumn('event_id', 'integer', []);$table->setPrimaryKey(['eventname_id']);$table->addIndex(['event_id']);//, 'IDX_65B8FBEC9B6B5FBZ', []);/** End of generate table oro_account_to_contact **//** Generate foreign keys for table orocrm_eventname_to_event **/$table = $schema->getTable('orocrm_eventname_to_event');$table->addForeignKeyConstraint($schema->getTable('oro_calendar_event'), ['event_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => null]);$table->addForeignKeyConstraint($schema->getTable('orocrm_eventname'), ['eventname_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => null]);/** End of generate foreign keys for table orocrm_eventname_to_event **/// @codingStandardsIgnoreEnd}}CalendarEvent Extension Migration file
123456789101112131415161718192021222324252627282930313233343536373839404142434445<?php// CalendarExtensionBundle/Migrations/Schema\v2_0\ExtendCalendarEntity.phpnamespace CampusCRM\CampusCalendarBundle\Migrations\Schema\v2_0;use Doctrine\DBAL\Schema\Schema;use Oro\Bundle\MigrationBundle\Migration\Migration;use Oro\Bundle\MigrationBundle\Migration\QueryBag;use Oro\Bundle\EntityExtendBundle\EntityConfig\ExtendScope;use Oro\Bundle\EntityBundle\EntityConfig\DatagridScope;use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtensionAwareInterface;use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtension;class ExtendCalendarEntity implements Migration, ExtendExtensionAwareInterface{protected $extendExtension;public function setExtendExtension(ExtendExtension $extendExtension){$this->extendExtension = $extendExtension;}public function up(Schema $schema, QueryBag $queries){$this->extendExtension->addManyToOneRelation($schema,'orocrm_eventname', // owning side table'eventname_id', // owning side field name'oro_calendar_event', // inverse side table'eventname_id', // column name is used to show related entity['extend' => ['owner' => ExtendScope::OWNER_CUSTOM]]);$this->extendExtension->addManyToOneInverseRelation($schema,'orocrm_eventname', // owning side table'eventname_id', // owning side field name'oro_calendar_event', // inverse side table'eventname_id', // inverse side field name['title'], // column names are used to show a title of owning side entity['description'], // column names are used to show detailed info about owning side entity['title'], // Column names are used to show owning side entity in a grid['extend' => ['owner' => ExtendScope::OWNER_CUSTOM]]);}}
The forum ‘Oro Community’ is closed to new topics and replies.