0

I'm quite new to Extbase and I'm trying to programmatically persist a new Model. The following code works:

$testModel = $this->objectManager->create('Tx_MyExtension_Domain_Model_Test');
$testModel->setName('testing');
$this->TestRepository->add($testModel);
$this->persistenceManager->persistAll();

However, I would like to change the storage folder it is put in (thus; change the pid field the record gets in the database). How should I do this?

user125661
  • 1,558
  • 12
  • 28

1 Answers1

3

You can set the default storage pid for new entries for a specific model in the typoscript setup of your extension:

plugin.tx_your_extension {
    persistence {
        classes {
            Tx_YourExtension_Domain_Model_YourModel.newRecordStoragePid = 74
        }
    }
}

Now all new models are saved in this location.

Merec
  • 2,751
  • 1
  • 14
  • 21
  • This works, thanks! Is there also a possibility to tell the persistence manager which storage pid to use (just for one method, not in general)? – user125661 Mar 05 '13 at 11:02
  • 2
    Yes you can add the column "pid" to your model and set it, this is the first the model looks at. But please put this in a new question. – Merec Mar 05 '13 at 12:58
  • To add to @Merec's comment: You can find more information about the whole process at http://alt.mimi.kaktusteam.de/index.php?id=mimis_blog&tx_t3blog_pi1%5BblogList%5D%5BshowUidPerma%5D=156&cHash=ab42d388c1f45f3a7d8cd4a5f607f581 – maryisdead Apr 15 '15 at 15:04
  • @Merec can you look at [my question](http://stackoverflow.com/questions/41266342/set-more-than-one-storage-pid-for-one-extension) and give a complete answer with your suggetion ... – webman Dec 23 '16 at 05:21