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 6680411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:28:19+00:00 2026-05-26T04:28:19+00:00

I edited some mistakes and details… Well, I have been trying to create a

  • 0

I edited some mistakes and details…

Well, I have been trying to create a inheritance with Product as parent and Film and Book as childs. Checking online and the official documentation didn’t solved my problem because examples are poor and incomplete. (http://www.doctrine-project.org/docs/orm/2.0/en/reference/inheritance-mapping.html#class-table-inheritance).

I’m not sure if I did it right and now I just don’t know how to generate, manipulate and persist inherited objects.

Parent class

<?php
namespace Paf\MyBundle\Entity;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Table()
 * @ORM\Entity
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="discr", type="string")
 * @ORM\DiscriminatorMap({ "film" = "FilmE2" , "book" = "BookE2" })
*/

class ProductEjemplo2 
{

/**
 * @var integer $id
 * @ORM\Id
 * @ORM\Column(name="id", type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;
//More fields, Name, Description ...
}

Child Class

<?php 
//Paf\MyBundle\Entity\FilmE2
namespace Paf\MyBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table()
* @ORM\Entity
*/

class FilmE2 extends ProductEjemplo2
{
/**
  * @var integer $id
  * @ORM\Id
  * @ORM\Column(name="id", type="integer")
  */
 protected $id;
}

doctrine:schema:update –force generates 2 tables:
ProductE…(id primary key, disc dunno how works, rest of fields)
FilmE2(id primary key, rest of fields)

public function create2Action()  
{
$product1 = new ProductEjemplo2();
$product1->setName('New Film 1'); //and more fields
//here $product1 ID is null.(autogenerated but yet without value)
$em->persist($product1); //error, non-object....
$em->flush();

$film = new FilmE2();
$film->setName('New Film 1'); //and more fields
$film->setDirector('dir1');
$film->setId(1);
$em->persist($film); //error, non-object....
$em->flush();
//In both cases happens the same.

This doesn’t work, it’s quite obvious because says error “non-object” cant be persisted… but if I try with a new Filme2() happens the same… I realized that the ID of product is autogenerated when I use flush(). So isn’t generated when I use persist…

  • 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-05-26T04:28:20+00:00Added an answer on May 26, 2026 at 4:28 am

    You cannot have two primary keys in inherited class, simply because it lets you to persist base object class. You can find an example here it works fine. Except that its more complicated to use queries witch should filter specific instances but everything is possible

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

Sidebar

Related Questions

Hi there I have edited some code I have found on-line and everything works
I have edited some files in working stage (not added them with git add
I have edited some cool scrollbars. I needed text to be in the middle,
I'm trying to set up XDebug for PHP. I edited some settings in my
I have modified and edited some project files in a folder targeted at a
Lets say i have an object that i created. I edited some values in
(Edited a lot) I've got some classes with Abstracts Members. The concrete type of
[Edited: After cross-testing on a fresh machine and some additional research, this appears to
My app needs to install some files that can be edited by the application
UPDATE: Edited javascript code. It's only slightly off now in some columns. Maybe a

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.