I have entities in a OneToMany relation:
Forecast -> has many -> Brick(s)
I've created serialization mappings for each in Resources/config/serializer/Entity.xxx.yml
where xxx is entity name.
Each entity has exclusion policy set to ALL and some of it's properties are exposed, eg:
Acme\ForecastBundle\Entity\Forecast:
exclusion_policy: ALL
xml_root_name: forecast
properties:
id:
expose: true
type: integer
regionUid:
expose: true
type: string
description:
expose: true
type: string
bricks:
expose: true
type: array<Acme\ForecastBundle\Entity\Brick>
xml_list:
inline: true
entry_name: brick
When in my template I do {{ forecast|serialize|raw }}
I am getting:
Forecast -> as I expected -> only exposed fields are serialized
Bricks collection -> all properties are serialized -> it seems that my Entity.Brick.yml
is ignored... why?
In brick I have only ID and name exposed.. but in serialized output I have all properties (created_at, updated_at.. and more).. why? They should be excluded by "exclusion_policy: ALL". It seems that config for nested collection is not used.
Acme\ForecastBundle\Entity\Brick:
exclusion_policy: ALL
xml_root_name: brick
properties:
id:
expose: true
type: integer
name:
expose: true
type: string
EDIT:
Yes, I did clear cache after each change in .yml config
After some suggestions I added @ExclusionPolicy("ALL") annotation to the Brick class and @Expose on ID, just to see what happens.. and suddenly it works! Not only ID is exposed, but everything is like in my YML configuration.
So I removed the annotations.. and it still works!
So it seems that adding Annotations somehow forced serializer to recognize my YML config. I don't know why though. That worries me.
Is it possible APC cache is guilty? I did clear Symfony2 cache numerous of times, but APC only a few.
Since there were no anwsers, I'll post what I eventually did/found out (for future reference and anyone who encounters the same problem). I'll quote my edit:
After some suggestions I added @ExclusionPolicy("ALL") annotation to the Brick class and @Expose on ID, just to see what happens.. and suddenly it works! Not only ID is exposed, but everything is like in my YML configuration.
So I removed the annotations.. and it still works!
So it seems that adding Annotations somehow forced serializer to recognize my YML config. I don't know why though. That worries me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With