Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty results serializing virtual_properties #400

Closed
danwkennedy opened this issue Feb 16, 2015 · 2 comments
Closed

Empty results serializing virtual_properties #400

danwkennedy opened this issue Feb 16, 2015 · 2 comments

Comments

@danwkennedy
Copy link

One of my classes that I'm serializing has a virtual property that I would like to see. I'm using yaml configuration.

Here's the yaml:

Namespace\Model\Keg:
   exclusion_policy: ALL
   properties:
      A list of properties that work
   virtual_properties:
      getKegImage:
         serialized_name: image

Here's the class:

namespace PintLabs\Service\SteadyServ\Model;

class Keg extends ModelAbstract
{
       /** Some properties + accessors **/

       /**
       * @param bool $asImgTag Whether or not to return the URL in an <img> tag
       * @return array
       */
       public function getKegImage ($asImgTag = false)
       {
               return [
                    'Key' => 'value',
                    'Key' => 'value',
                    'Key' => 'value'
               ];
       }
}

When I serialize the model, I would expect the to see an image field in the json with the array as its value. Instead, the field is missing. I've tried many combinations of settings in the yaml file and I can't get it to show.

@danwkennedy
Copy link
Author

As an update, I tried running the unit tests and the tests pertaining to the test fixtures with virtual properties passed. However, I deleted the yml virtual properties and the tests still passed so I doubt those fixtures actually had an impact on the tests.

@danwkennedy
Copy link
Author

From looking at the code, it looks like virtual properties aren't actually supported using yaml metadata. Luckily, you can mix metadata sources if you want. I simply added the @VirtualProperty Doctrine annotation to the method and it worked as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant