[Flow] Ignore validation errors for related object
Steffen Wickham
steffen at gaming-inc.de
Tue May 21 11:02:44 CEST 2013
Hello Stephen,
your implementation looks good. I had some similar problems with one of
my types some days ago. I had to set a proper "Position" object within
my "RefereeAssignment" model but I can't update or create these
RefereeAssignment models until I changed my setter method like this:
/**
* Set the corresponding position for this assignment
*
* @param \AFSVN\Basic\Domain\Model\Position $positionReference
* @throws \Exception
* @return void
*/
public function setPosition( $positionReference ) {
if ( $positionReference === NULL || $positionReference instanceof
\AFSVN\Basic\Domain\Model\Position) {
$this->position = $positionReference;
} else {
throw new \Exception('Position can only be an instance of
\AFSVN\Basic\Domain\Model\Position or NULL');
}
}
So I can provide a NULL value or the correct Position and depending on
the value, it get set correctly. Now I can create and update all
RefereeAssignments disregarding if a position is set or not.
And yes: I know that there is a proper Exception type for this but I'm a
bit lazy ;)
Maybe you can give it a try?
Cheers,
Steffen
Am 21.05.13 10:40, schrieb Stephen Bungert:
> Hello Steffen,
>
> Here is the property definition for my books image property:
>
> ---
> /**
> * The book's image.
> *
> * @var \Bungert\Library\Domain\Model\Image
> * @ORM\OneToOne(cascade={"all"}, orphanRemoval=true)
> * @ORM\Column(nullable=TRUE)
> */
> protected $image = NULL;
> ---
>
> And these are my image getters/setters:
>
> ---
> /**
> * Sets image.
> *
> * @param \Bungert\Library\Domain\Model\Image $image The image for this
> book.
> * @return void
> */
> public function setImage(\Bungert\Library\Domain\Model\Image $image = NULL)
> {
> $this->image = $image;
> }
>
> /**
> * Gets image.
> *
> * @return \Bungert\Library\Domain\Model\Image The book's image.
> */
> public function getImage() {
> return $this->image;
> }
>
> /**
> * Removes image.
> *
> * @return void
> */
> public function removeImage() {
> $this->image = NULL;
> }
> ---
>
> I can create images when I make a book, I can delete images, my probem is
> that I can't create a book unless I make an image. I want the image to be
> optional
>
> I'm not sure that it matters, but I also have an initialise update action:
>
> ---
> public function initializeUpdateAction() {
> $propertyMappingConfiguration =
> $this->arguments['book']->getPropertyMappingConfiguration();
> $propertyMappingConfiguration->allowProperties('genres', 'image');
> $propertyMappingConfiguration->setTypeConverterOption(
> 'TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter',
> \TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED,
> TRUE
> );
> }
> ---
>
> That was necessary so that while creating books I could assign/unasign genre
> records (mayntomany relationship) to the books, but I also had to add image
> as one of the allowed properties. maybe this function isn't correctly done?
>
> "Steffen Wickham" <steffen at gaming-inc.de> schrieb im Newsbeitrag
> news:mailman.151.1369125031.570.flow at lists.typo3.org...
>> Hello Stephen,
>>
>> did you add "@ORM\Column(nullable=true)" to your image property? How do
>> you annotate the property and implement the setter/getter methods for
>> it? Please provide us a little bit more details :)
>>
>> Best regards,
>> Steffen
>>
>>
>> Am 19.05.13 11:30, schrieb Stephen Bungert:
>>> I have a form for my main objects - books, they have a onetoone
>>> relationship with another object - an image, but an image isn't
>>> required. The problem is, that this object has two fields that are
>>> required, so my main object's update action reports validation errors.
>>>
>>> I can create books with images, and images can be deleted too, but I
>>> can't save my book without validation errors because of the required
>>> fields in the image object.
>>>
>>> Is there anyway of over-riding these errors in my book's update action?
>>>
>>> Thanks for any help.
>>>
>>> Stephen.
>>> _______________________________________________
>>> Flow mailing list
>>> Flow at lists.typo3.org
>>> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
>
> _______________________________________________
> Flow mailing list
> Flow at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
More information about the Flow
mailing list