[Flow] Converting Objects by additional identity does not work?
Alexander Berl
a.berl at outlook.com
Wed Mar 5 15:24:16 CET 2014
Hi Carsten,
I had to take some deep looks in the Flow code to understand, but I
think I know what the problem is.
First of all, there is a difference between the persistence identifier
(Persistence_Object_Identifier magic attribute or class attribute
annotated with @ORM\Id) and an @Flow\Identity annotated attribute.
The latter is not connected to the database primary key, but is
supposedly used to identify entities by alternative unique attributes.
Now what happens in 2.) is this:
Since you don't use the identity route part handler in your route
configuration, the external identity string is just forwarded directly
to the property mapping/type converter.
However, the PersistentObjectTypeConverter expects a string type
identifier to be the persistence identifier and tries to retrieve the
object by that.
This will obviously not match, as the primary key is the
Persistence_Object_Identifer.
The PersistentObjectTypeConvert only falls back to retrieving the object
by the additional identity when the value is an array.
This may be arguable behaviour, but so far is supposed to work if you
use the IdentityRoutePart configuration, to tell the Routing that you
expect an entity that is given by its identifier, which would in turn be
converted to array('__identity' => $value), so the TypeConverter would
work as expected.
Now, there is another problem with the
IdentityRoutePartHandler::getObjectIdentifierFromPathSegment:
If you don't set an Uri pattern, it in turn will also try to check the
given identity against the persistence identity (which again fails).
If you do set an Uri pattern (or have your entity annotated with
@Flow\Identity attributes), it only works if the route part is cached,
e.g. you created an URI to that entity beforehand.
I guess that's something that has to be discussed with the core
developers, as the behaviour is not quite consequent, but too deep to
give a quick solution.
As for your actual problem I see two possible solutions:
1.) Use the identity route configuration. You'd need to pre-create the
cache entries though, which might be problematic.
2.) Completely skip the magic Persistence_Object_Identifier by
annotating your external Id with @Orm\Id instead of @Flow\Identity
Regards,
Alexander
Am 05.03.2014 13:12, schrieb Carsten Bleicker:
> Runnig a test in the frontend with a test action wich redirects me to the show action of a given artist works:
>
> 1.) $this->redirect('show',array('resource' => $foo)) results in:
> http://development.artmanager.local/foo/artist/test/fc700953-8911-9432-542e-968b7bff43e3
> Status 200
>
> 2.) $this->redirect('show',array('resource' => $foo->getForeignIdentity())) results in:
> http://development.artmanager.local/foo/artist/test/5317133a3e1bb <-- foreignIdentity wich is also a @Flow\Identity
> Status 500
> #1297933823: Object with identity "5317133a3e1bb" not found.
>
>
> Am 05.03.2014 um 12:14 schrieb Carsten Bleicker <carsten at bleicker.de>:
>
>> hi folks,
>> having an entity with the default flow persistence identity and also another identity:
>>
>> // @Flow\Entity
>> class Foo{
>>
>> /**
>> * @var string
>> * @Flow\Identity
>> */
>> protected $foreignIdentity;
>>
>> }
>>
>>
>> my routing:
>> -
>> name: 'Read Action with foreignIdentity as {foo}'
>> uriPattern: 'rest/{foo}'
>> httpMethods: ['GET']
>> defaults:
>> '@package': 'Foo.Bar'
>> '@controller': 'Foo'
>> '@action': 'read'
>> '@format': 'json'
>>
>>
>> I would expect that my controller receives the mapped entity, detected either by its foreignIdentity or by its flow_persistence_identifier.
>> But only flow_persistence_identifier works.
>>
>> Am i wron with my expectation?
>> _______________________________________________
>> Flow mailing list
>> Flow at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
>
More information about the Flow
mailing list