CC-5896: Store cloud files in separate table, inherited from cc_files

Added delete on cascade for cloud files
This commit is contained in:
drigato 2014-07-28 16:03:57 -04:00
parent f6aa2e5a3b
commit 6fa7ddba9a
6 changed files with 12 additions and 9 deletions

View File

@ -120,7 +120,7 @@ class CcFilesTableMap extends TableMap
$this->addRelation('FkOwner', 'CcSubjs', RelationMap::MANY_TO_ONE, array('owner_id' => 'id', ), null, null);
$this->addRelation('CcSubjsRelatedByDbEditedby', 'CcSubjs', RelationMap::MANY_TO_ONE, array('editedby' => 'id', ), null, null);
$this->addRelation('CcMusicDirs', 'CcMusicDirs', RelationMap::MANY_TO_ONE, array('directory' => 'id', ), null, null);
$this->addRelation('CloudFile', 'CloudFile', RelationMap::ONE_TO_MANY, array('id' => 'cc_file_id', ), null, null, 'CloudFiles');
$this->addRelation('CloudFile', 'CloudFile', RelationMap::ONE_TO_MANY, array('id' => 'cc_file_id', ), 'CASCADE', null, 'CloudFiles');
$this->addRelation('CcShowInstances', 'CcShowInstances', RelationMap::ONE_TO_MANY, array('id' => 'file_id', ), 'CASCADE', null, 'CcShowInstancess');
$this->addRelation('CcPlaylistcontents', 'CcPlaylistcontents', RelationMap::ONE_TO_MANY, array('id' => 'file_id', ), 'CASCADE', null, 'CcPlaylistcontentss');
$this->addRelation('CcBlockcontents', 'CcBlockcontents', RelationMap::ONE_TO_MANY, array('id' => 'file_id', ), 'CASCADE', null, 'CcBlockcontentss');

View File

@ -39,7 +39,7 @@ class CloudFileTableMap extends TableMap
$this->setUseIdGenerator(true);
$this->setPrimaryKeyMethodInfo('cloud_file_id_seq');
// columns
$this->addPrimaryKey('id', 'Id', 'INTEGER', true, null, null);
$this->addPrimaryKey('id', 'DbId', 'INTEGER', true, null, null);
$this->addColumn('resource_id', 'ResourceId', 'LONGVARCHAR', true, null, null);
$this->addForeignKey('cc_file_id', 'CcFileId', 'INTEGER', 'cc_files', 'id', false, null, null);
// validators
@ -50,7 +50,7 @@ class CloudFileTableMap extends TableMap
*/
public function buildRelations()
{
$this->addRelation('CcFiles', 'CcFiles', RelationMap::MANY_TO_ONE, array('cc_file_id' => 'id', ), null, null);
$this->addRelation('CcFiles', 'CcFiles', RelationMap::MANY_TO_ONE, array('cc_file_id' => 'id', ), 'CASCADE', null);
} // buildRelations()
/**

View File

@ -3405,10 +3405,9 @@ abstract class BaseCcFiles extends BaseObject implements Persistent
if ($this->cloudFilesScheduledForDeletion !== null) {
if (!$this->cloudFilesScheduledForDeletion->isEmpty()) {
foreach ($this->cloudFilesScheduledForDeletion as $cloudFile) {
// need to save related object because we set the relation to null
$cloudFile->save($con);
}
CloudFileQuery::create()
->filterByPrimaryKeys($this->cloudFilesScheduledForDeletion->getPrimaryKeys(false))
->delete($con);
$this->cloudFilesScheduledForDeletion = null;
}
}

View File

@ -700,6 +700,9 @@ abstract class BaseCcFilesPeer
*/
public static function clearRelatedInstancePool()
{
// Invalidate objects in CloudFilePeer instance pool,
// since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
CloudFilePeer::clearInstancePool();
// Invalidate objects in CcShowInstancesPeer instance pool,
// since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
CcShowInstancesPeer::clearInstancePool();

View File

@ -103,7 +103,7 @@
<column name="id" phpName="DbId" required="true" primaryKey="true" autoIncrement="true" type="INTEGER"/>
<column name="resource_id" phpName="ResourceId" type="LONGVARCHAR" required="true"/>
<column name="cc_file_id" type="INTEGER"/>
<foreign-key foreignTable="cc_files">
<foreign-key foreignTable="cc_files" onDelete="CASCADE">
<reference local="cc_file_id" foreign="id"/>
</foreign-key>
<behavior name="delegate">

View File

@ -694,7 +694,8 @@ ALTER TABLE "cc_files" ADD CONSTRAINT "cc_music_dirs_folder_fkey"
ALTER TABLE "cloud_file" ADD CONSTRAINT "cloud_file_FK_1"
FOREIGN KEY ("cc_file_id")
REFERENCES "cc_files" ("id");
REFERENCES "cc_files" ("id")
ON DELETE CASCADE;
ALTER TABLE "cc_perms" ADD CONSTRAINT "cc_perms_subj_fkey"
FOREIGN KEY ("subj")