Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8293409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:49:06+00:00 2026-06-08T13:49:06+00:00

I have created an inherited document class, see the code below. The documents persists

  • 0

I have created an inherited document class, see the code below. The documents persists fine but when fetching the document and trying to call the children’s function, I will get an error Call to undefined method Proxies__CG__\Acme\ProductBundle\Document\ProductBase::getPriceDefinition() even the child document has getPriceDefinition() function. The proxy points also to the ProductBase, not SimpleProduct.

The parent class, ProductBase.php

<?php
namespace Acme\ProductBundle\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

/**
 * @MongoDB\Document
 * @MongoDB\InheritanceType("SINGLE_COLLECTION")
 * @MongoDB\DiscriminatorField(fieldName="type")
 * @MongoDB\DiscriminatorMap({"simple"="SimpleProduct"})
 */
abstract class ProductBase
{   
    /**
     * @MongoDB\Id;
     */
    protected $_id;

    /**
     * @MongoDB\String
     */
    public $comment;
}

The child class, SimpleProduct.php

<?php
namespace Acme\ProductBundle\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

/**
 * @MongoDB\Document
 */
class SimpleProduct extends ProductBase
{

    /**
     * @var PriceDefinition
     * @MongoDB\EmbedOne(targetDocument="PriceDefinition") 
     */
    protected $priceDefinition;

    public function getPriceDefinition() {
        return $this->priceDefinition;
    }
}

Calling code (only partial):

$product = $this->dm->getRepository('AcmeProductBundle:Product')->findOneBy(array('_id' => $productId));
$priceDefinition = $product->getPriceDefinition(); // The error is thrown here

Finally the document in the database (that is persisted with the above documents correctly).

{
  "_id": ObjectId("5006d7b76803fa9403000007"),
  "priceDefinition": {
     "referenceValue": 1000000,
     "currency": "iso: EUR",
     "taxBehavior": "fi_vat_a",
     "isGrossPrice": false
  },
  "type": "simple"
}   

In general this somehow seems that Doctrine would not recognize that the returned object is a subclass. But – if I for example change the database type value to something else than “simple” (for example “not-simple”) that does not match the DiscriminatorMap, the Doctrine says “Notice: Undefined index: not-simple (…)”.

And what the strangest, as soon as I add getPriceDefinition() in the parent class (ProductBase), it gets called properly and without errors.

Uhh… that was a long question. Anyhow, I am just unable to find out what’s the problem here. Is it my getRepository(‘AcmeProductBundle:Product’) call, or my inheritance definitions…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T13:49:08+00:00Added an answer on June 8, 2026 at 1:49 pm

    Given that ProductBase is abstract, is there any reason you’re not annotating it as a MappedSuperclass? ODM is constructing a proxy that extends ProductBase (it does so between your findOneBy() call and attempting to call getPriceDefinition()), which doesn’t make sense in practice. Proxy objects are meant to be used interchangeably with the mapped class — in this case, the proxy is extending an abstract class which should never exist on its own. Even so, it seems like this odd mapping is causing a bug in the discriminator logic, as that type field should cause SimpleProduct to be used.

    Also, changing the database value of the type field to not-simple should not cause the code to elicit a PHP notice. We should be throwing an exception instead.

    Would you mind opening separate issues for both of these bugs in the GitHub repository? If you’re feeling up to it, failing test cases would be welcome as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a register form created by mvc3 scaffolding. e.g. <div class=editor-label> @Html.LabelFor(model =>
I have created custom validation attribute [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited =
I have a model as shown below (created using Model-First approach). A book is
I have the code to this open source Message Console in java, but it
I have an XML document that has been created using utf-8 encoding. I want
I have 2 multi-table inherited models like these: class Post(models.Model): title = models.CharField(max_length=100, blank=True,
I have created an iframe code that I want people to use as a
In a Visual Studio website, I have created a user control. This control is
I have created the application which is based on Sqlite database. So in my
Lets say I have the following code that returns number of anchor elements on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.