Commit eb066b86 authored by Julien Fastré's avatar Julien Fastré
Browse files

add foreign key from report to scope

parent 1c3c3b14
......@@ -24,10 +24,14 @@ use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
namespace Chill\ReportBundle\Entity;
use Chill\MainBundle\Entity\HasCenterInterface;
use Chill\MainBundle\Entity\HasScopeInterface;
use Chill\MainBundle\Entity\Scope;
/**
* Report
*/
class Report
class Report implements HasCenterInterface, HasScopeInterface
{
/**
* @var integer
......@@ -50,7 +54,7 @@ class Report
private $date;
/**
* @var string
* @var Scope
*/
private $scope;
......@@ -154,7 +158,7 @@ class Report
*
* @return Report
*/
public function setScope($scope)
public function setScope(Scope $scope)
{
$this->scope = $scope;
......@@ -164,7 +168,7 @@ class Report
/**
* Get scope
*
* @return string
* @return Scope
*/
public function getScope()
{
......@@ -218,4 +222,10 @@ class Report
{
return $this->cFGroup;
}
public function getCenter()
{
return $this->person->getCenter();
}
}
\ No newline at end of file
......@@ -10,10 +10,6 @@ Chill\ReportBundle\Entity\Report:
fields:
date:
type: datetime
scope:
type: string
length: 255
nullable: true # TO REMOVE IF SCOPE IS USED
cFData:
type: json_array
manyToOne:
......@@ -21,6 +17,8 @@ Chill\ReportBundle\Entity\Report:
targetEntity: Chill\MainBundle\Entity\User
person:
targetEntity: Chill\PersonBundle\Entity\Person
scope:
targetEntity: Chill\MainBundle\Entity\Scope
cFGroup:
targetEntity: Chill\CustomFieldsBundle\Entity\CustomFieldsGroup
lifecycleCallbacks: { }
\ No newline at end of file
<?php
namespace Application\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Add a scope to report
*/
class Version20150622233319 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql',
'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE report ADD scope_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE report DROP scope'); //before this migration, scope was never used
$this->addSql('ALTER TABLE report ADD CONSTRAINT FK_report_scope '
. 'FOREIGN KEY (scope_id) '
. 'REFERENCES scopes (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_report_scope ON report (scope_id)');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql',
'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE Report DROP CONSTRAINT FK_C38372B2682B5931');
$this->addSql('DROP INDEX IDX_C38372B2682B5931');
$this->addSql('ALTER TABLE Report ADD scope VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE Report DROP scope_id');
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment