2013-02-13 20:42:13 -02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
2016-12-08 18:01:04 +01:00
|
|
|
use Doctrine\Tests\Models\Cache\Attraction;
|
|
|
|
use Doctrine\Tests\Models\Cache\State;
|
|
|
|
use Doctrine\Tests\Models\Cache\Travel;
|
2013-02-13 20:42:13 -02:00
|
|
|
|
|
|
|
$metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
|
2016-12-07 23:33:41 +01:00
|
|
|
$metadata->setPrimaryTable(['name' => 'cache_city']);
|
2013-02-13 20:42:13 -02:00
|
|
|
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_IDENTITY);
|
|
|
|
$metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT);
|
|
|
|
|
2016-12-07 23:33:41 +01:00
|
|
|
$metadata->enableCache(
|
|
|
|
[
|
2013-02-13 20:42:13 -02:00
|
|
|
'usage' => ClassMetadataInfo::CACHE_USAGE_READ_ONLY
|
2016-12-07 23:33:41 +01:00
|
|
|
]
|
|
|
|
);
|
2013-02-13 20:42:13 -02:00
|
|
|
|
2016-12-07 23:33:41 +01:00
|
|
|
$metadata->mapField(
|
|
|
|
[
|
2013-02-13 20:42:13 -02:00
|
|
|
'fieldName' => 'id',
|
|
|
|
'type' => 'integer',
|
|
|
|
'id' => true,
|
2016-12-07 23:33:41 +01:00
|
|
|
]
|
|
|
|
);
|
2013-02-13 20:42:13 -02:00
|
|
|
|
2016-12-07 23:33:41 +01:00
|
|
|
$metadata->mapField(
|
|
|
|
[
|
2013-02-13 20:42:13 -02:00
|
|
|
'fieldName' => 'name',
|
|
|
|
'type' => 'string',
|
2016-12-07 23:33:41 +01:00
|
|
|
]
|
|
|
|
);
|
2013-02-13 20:42:13 -02:00
|
|
|
|
|
|
|
|
2016-12-07 23:33:41 +01:00
|
|
|
$metadata->mapOneToOne(
|
|
|
|
[
|
2013-02-13 20:42:13 -02:00
|
|
|
'fieldName' => 'state',
|
2016-12-08 18:01:04 +01:00
|
|
|
'targetEntity' => State::class,
|
2013-02-13 20:42:13 -02:00
|
|
|
'inversedBy' => 'cities',
|
|
|
|
'joinColumns' =>
|
2016-12-07 23:33:41 +01:00
|
|
|
[
|
|
|
|
[
|
2013-02-13 20:42:13 -02:00
|
|
|
'name' => 'state_id',
|
|
|
|
'referencedColumnName' => 'id',
|
2016-12-07 23:33:41 +01:00
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$metadata->enableAssociationCache('state', [
|
2013-02-13 20:42:13 -02:00
|
|
|
'usage' => ClassMetadataInfo::CACHE_USAGE_READ_ONLY
|
2016-12-07 23:33:41 +01:00
|
|
|
]
|
|
|
|
);
|
2013-02-13 20:42:13 -02:00
|
|
|
|
2016-12-07 23:33:41 +01:00
|
|
|
$metadata->mapManyToMany(
|
|
|
|
[
|
2013-02-13 20:42:13 -02:00
|
|
|
'fieldName' => 'travels',
|
2016-12-08 18:01:04 +01:00
|
|
|
'targetEntity' => Travel::class,
|
2013-02-13 20:42:13 -02:00
|
|
|
'mappedBy' => 'visitedCities',
|
2016-12-07 23:33:41 +01:00
|
|
|
]
|
|
|
|
);
|
2013-02-13 20:42:13 -02:00
|
|
|
|
2016-12-07 23:33:41 +01:00
|
|
|
$metadata->mapOneToMany(
|
|
|
|
[
|
2013-02-13 20:42:13 -02:00
|
|
|
'fieldName' => 'attractions',
|
2016-12-08 18:01:04 +01:00
|
|
|
'targetEntity' => Attraction::class,
|
2013-02-13 20:42:13 -02:00
|
|
|
'mappedBy' => 'city',
|
2016-12-07 23:33:41 +01:00
|
|
|
'orderBy' => ['name' => 'ASC',],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$metadata->enableAssociationCache('attractions', [
|
2013-02-13 20:42:13 -02:00
|
|
|
'usage' => ClassMetadataInfo::CACHE_USAGE_READ_ONLY
|
2016-12-07 23:33:41 +01:00
|
|
|
]
|
|
|
|
);
|