I made an extbase extension with a class Appointment
with a property expertises
und another one subExpertises
of the same type.
This is how they look like in the Appointment
class (subExpertises
is the same):
/**
* expertises
*
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<...\Domain\Model\Expertise>
*/
protected $expertises = NULL;
/**
* Adds an expertise
*
* @param ...\Domain\Model\Expertise $expertise
* @return void
*/
public function addExpertise(...\Domain\Model\Expertise $expertise) {
$this->expertises->attach($expertise);
}
I get an error when executing this code in my controller after editing the appointment in a fluid form:
/**
*
* @param \Domain\Model\Appointment $appointment
* @return void
*/
public function bookAction(\Domain\Model\Appointment $appointment) {
//empty all expertises of appointment - then fill them with the selected from lawyer
$appointment->setExpertises(new \TYPO3\CMS\Extbase\Persistence\ObjectStorage());
$appointment->setSubExpertises(new \TYPO3\CMS\Extbase\Persistence\ObjectStorage());
//add all checked expertises of lawyer to appointment
foreach ($appointment->getLawyer()->getExpertises() as $expertise) {
if ($expertise->getChecked()) {
$appointment->addExpertise($expertise);
}
foreach ($expertise->getSubExpertises() as $subExpertise) {
if ($subExpertise->getChecked()) {
$appointment->addSubExpertise($subExpertise);
}
}
}
$this->appointmentRepository->update($appointment);
}
This is the error:
Fatal error: Call to undefined method \Domain\Model\Expertise::getPosition() in /var/www/typo3_src/typo3_src-6.2.25/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php on line 453
Now it seems that TYPO3 thinks Expertise
is of type ObjectStorage
because it tries to call getPosition()
but I have no clue why it does that and what I should change in order to successfully save my Appointment
object with the new Expertises
.
I tried debugging the appointment object, but I couldn't find the problem - it seems okay to me, it just shows that expertises
und subExpertises
have been modified.
expertises
andsubExpertises
the class name isExpertise
andaddExpertise
only adds one, so it should be singular – Cold_Class